PHP - How To Display An Array Horizontally In A Set Number Of Rows?
Hi Guys!
Trying to display data in 3 rows horizontally and 25 vertiacally Code: [Select] // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(biddersId)'] ." bidders logged."; echo "<br />"; } $query = "SELECT * FROM bidders ORDER BY biddersId"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Bidders</th>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</br>"; echo "</td><td>"; } echo "</table>"; ?> Similar TutorialsPlease help me. I'm fairly new to php and have been looking for answers on Goog for about two weeks or so with not an answer. This is my first post on a forum of any type. I have a form on a php page that when submitted sends a value to a confirm php page Code: [Select] <form action='buyconfirmorder.php' method='post'> Purchase: <input type='text' name='ask_shares'><br /><br /> You Will Pay:  <input type='text' name='ask'><br /><br /> <input type='hidden' name='postcardname' value='$postcardname'> <input type='submit' name='submit' value='Order'> </form> I need to take the users input from the form and subtract each row from a mysql DB one at a time until the users input is down to a remainder and then I need the remainder (I'll be working with the remainder as well). Code: [Select] $query = mysql_query(" SELECT * FROM ask, search WHERE search.id = ask.card_search_id AND search.card_name = '$postcardname' ORDER BY ask_price ASC"); The array will be numbers only. So an example would be: User input from the form is 100.00 Code: [Select] while($rows = mysql_fetch_array($query)) { $ask_price = $rows['ask_price']; } Let's say the array is 50.50, 40.50, 35.00 I need some code to do: 100.00 - 50.50 = 49.50 49.50 - 40.50 = 9.00 9.00 - 35.00 = <0 does not do anything so remainder = 9.00 would it be something like Code: [Select] $new_ask_shares = $_POST['ask_shares']; //some sort of a loop or array or combo of both ($new_ask_shares - $ask_price); the numbers are just an example as the actual numbers will be different each time I query my DB. Thanks in advance I've got my code working OK in that the correct results are drawn from the database. What I have here in the code is an array consisting of an image, accompanied by its title and thirdly a link to activate a quiz associated with the image. Everything works fine, except because the page is dynamic, I always have an unknown number of sets of data (image, title and link) which I want to display so that each set of data takes up a new row. The code I have here, while displaying the correct data, places all of the results into the same row. Any suggestions are most welcome. Code: [Select] <?php // Query the database $query1 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query2 = mysql_query("SELECT url_small FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query3 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); while($row1 = mysql_fetch_array($query3)) { $linkname .= $row1['title']."<br />\n"; } ?> <table> <tr> <td> <?php while ($row2 = mysql_fetch_array($query2)) { $thumbnail.= $row2['url_small']; echo "<img src='wood_tool_images/{$row2['url_small']}' alt='' /><br />\n"; } ?> </td> <td height="200"> <?php echo $linkname ?> </td> <td> <?php while ($row1 = mysql_fetch_array($query1)) { $quizname.= $row1['title']; echo "<a href='../{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; } ?> </td> </tr> </table> I need to display a number(the number is retrieved from the db) in the form input field such that only the last 4 digits is visbile, the remaining can be masked as * or X or whatever is applicable. I know the last 4 can be obtained as follows: Code: [Select] $number=substr($number,-4,4); But when i hit the submit button the form validates the input field and checks if the number is a valid number of a specific format. Therefore when I click on the submit button then I should still be able to unmask the masked numbers or do something similar that would help me validate the whole number. Code: [Select] <input type="text" name="no" value="<?php if(!empty($number)){ echo $number;} ?>"> Hi I wanted to know how once I have selected and echoed the rows from mysql table how can I get it to number those rows that echo? etc 1. echo $variable 2. echo $variable 3. echo $variable 4. echo $variable 5. echo $variable Any help is appreciated I was just wondering when you run a mysql query what the easiest way to find out the number of rows returned. Just so I can do a number of results found on a search. Thanks. Hi, I have a problem regarding counting rows in a mysql table. Here is the code: Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect('read'); $check = 'SELECT COUNT(*) FROM images'; $checkRes = $conn->query($check) or die(mysqli_error()); if($checkRes <= 0) { header('Location: empty_blog.php'); // redirect to another page } else { // do something else... } ?> The error I'm getting: "Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\photoblog\index.php on line 6" Any help is greatly appreciated! Hey guys was wondering if anyone could modify the code below to have $output = 'yes' if the number of rows equal 10, 20, 30, 40, 50, 60, 70, 80......... etc $dbhost = '******'; $dbuser = ''******';'; $dbpass = ''******';'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('MYSQL N/A - Please Contact Admin'); $dbname = ''******';'; mysql_select_db($dbname); $query="SELECT * FROM documentaryinfo"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close($conn); ?> Thanks -------------------------------------------------------------------------------------------------------- Watch Free Documentaries Online - The Documentary Database www.free-documentaries-online.com -------------------------------------------------------------------------------------------------------- I have a html table displaying data from mysql database. I can count rows properly with mysql_num_rows but is there a way to echo which row number it is. What I want to do is count the rows ordered by cities and echo row number. Thanks for any help. Folks, Having trouble here. Forgot how you use the COUNT. Not interested in the num_rows due to it being slow compared to COUNT. I have users table like this: id|username|sponsor_username 0|barand|requinix 1|phpsane|alison 2|mickey_mouse|requinix Now, I want to check if a sponsor username exists or not. Such as does the entry "requinix" exists or not in one of the rows in the "sponsor_username" column. In our example it does twice and so the variable $sponsor_username_count should hold the value "2". Else hold "0". I get error: Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
My code:
$stmt_1 = mysqli_prepare($conn,"SELECT COUNT(sponsor_username) from users = ?"); mysqli_stmt_bind_param($stmt_1,'s',$sponsor_username_count); mysqli_stmt_execute($stmt_1); //Show error if 'users' tbl was not successfully queried". if (!$stmt_1) { echo "ERROR 1: Sorry! Our system is currently experiencing a problem loading this page!"; exit(); } else { mysqli_stmt_bind_result($stmt_1,$sponsor_username_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Check if Sponsor Username in Url ($_GET) is already registered or not. If not then show "Invalid Url" or Link message. if ($sponsor_username_count < 1) { echo "<b>Invalid Url or Link!<br> Invalid Sponsor: \"$sponsor_username\"!</b><?php "; exit(); } }
Hi Please take a look at my code snippet. I don't know how to get the number of rows returned from a MySQL stored procedure so that I can handle it accordingly. Any ideas please? Thanks hello, all: I'm a newbie, and been trying to work out a way so that the results from an array (or mysql recordset for that matter), are nicely aranged in a table. I want them to show in a grid-like manner, with rows and columns added according to number of "items". I worked out this small code snippet, with a sample array, and for the life of me, cant figure out how to make it so it automatically "breaks" columns at 5 and start new row. I got it to show me right number of rows, but then it repeats all 10 names within them, as opposed to just showing 5 names in each row... Appreciate the help... Code: [Select] <?php $names = array('Charles','Henry','Manny','Philip','Rose','Evelyn','Peter','Julia','Cary','Sophia'); $numberColumns = 5; $numberNames = count($names); $numberRows = ceil($numberNames / $numberColumns); echo "<table border='1' width='400' cellspacing='0' cellpadding='0'>"; for ($i=1; $i<=$numberRows; $i++) { echo "<tr>"; foreach ($names as $name) { echo "<td>" . $name . "</td>"; } echo "</tr>"; } echo "</table>"; ?> Hi All,
I'm looking to update a mysql column weekly, where by 5 randomly selected rows are given a new random number, from between 1 and the num_rows / 5. This cycle is looped again until all the entries have a new random group for the week. It is to help mix up the players for teams for 5 aside. It needs to be able to accomodate the posibillity of the num_rows not dividing exactly by 5, using ceil perhaps?
As an example
Name Group
a 1
b 2
c 1
d 1
e 1
f 3
g 2
h 1
i 2
j 2
k 2
Then Next week
Name Group
a 2
b 1
c 2
d 2
e 1
f 2
g 3
h 1
i 2
j 1
k 1
I hope that makes sense. It'll be automated via cron job.
I've been really struggling with it, this is as far as I have got.
$totalgroupsraw = $num_rows /5; I have a mysql table that holds data for cars - each car has it's own ID, name, and year. Some cars are repeated. Example: (ID - year - car name) 0001 - 2009 - Honda Civic 0002 - 2008 - Toyota Prius 0003 - 2009 - Honda Civic 0004 - 2008 - Toyota Prius 0005 - 2008 - Toyota Prius 0006 - 2007 - Honda Civic How would I count how many of the same type of cars I have in that table and then display the quantity next to the car name? Like for the above example it would be: 2009 Honda Civic: 2 2007 Honda Civic: 1 2008 Toyota Prius: 3 Thanks in advance for any help :D <?php require_once('upper.php'); require_once('database.php'); if(isset($_COOKIE['LoginIdCookie'])) { echo '<h4>Welcome '.$_COOKIE['LoginIdCookie'].'</h4>'; } else{ echo '<h4>Events</h4>';} $result=mysqli_query($dbc,"select * from events") or die('Not Connected'); echo "<html> <body>"; echo "<form method='post' action='EventParticipator.php'>"; echo "<u><h4>Please tick events in which you want to participate</h4></u>"; /*echo "<table cellspacing='0' cellpadding='15'> <th><b>Event Title:</b></th> <th ><b>Event City:</b></th> <th><b>Content:</b></th> <th><b>Images:</b></th> <th><b>Event Date:</b></th>";*/ //while($row=mysqli_fetch_array($result)) $row=mysqli_fetch_array($result); for($i=0;$i<5;$i++) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<tr><td><img src='$Photo' width='120' height='90'/></td><td>$City</td><td>,</td><td>$Date</td><td>:</td><td>$Title</td></tr> <tr><td>$Content</td></tr> <tr><td><a href='#'>Know more</a></td><td>/</td><td><a href='#'>Click here to participate</a></td></tr>"; } //echo "<tr><td><input type='submit' name='submit' value='Participate'</td>"; if(isset($_COOKIE['LoginIdCookie'])) { echo "<td><a href='log_out.php'>Log out</a></td>"; echo "<td><a href='EditActivity.php'>Edit Your Activities</a></td></tr>"; } echo "</table></form></body></html>"; require_once('lower.php'); ?> Quote Hi friends .......... I write above code to display top 5 rows from the database but it not works properly. It displays first row 5 times which is undesireable. Anyone please help????????????????? thanks in advance.................. Hey guys! I've been having trouble with this all day. I'm wanting to display my results in rows. Like, 4 results in 1 row, then another 4, then another 4, etc. like this: IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE I'm nto sure how to do that. I want to display pictures. Here is my code for the page: bag.php: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Inventory</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Inventory</font><br><br>"; $action = $_GET['action']; $gid = $_GET['itemid']; $irow = "SELECT * FROM uitems WHERE username='$showusername'"; $iquery = mysql_query($irow); while($ir = mysql_fetch_array($iquery)) { $uid = $ir['uitemid']; $iid = $ir['theitemid']; $iun = $r['username']; $il = $ir['location']; $tirow = "SELECT * FROM items WHERE itemid='$iid'"; $tiquery = mysql_query($tirow); while($tir = mysql_fetch_array($tiquery)) { $tiid = $tir['itemid']; $tin = $tir['name']; $tiim = $tir['image']; $tid = $tir['description']; $tirr = $tir['rarity']; $tit = $tir['type']; $tiu = $tir['uses']; $tis = $tir['strength']; $tide = $tir['defense']; $tih = $tir['heals']; echo "<img src=/images/items/$tiim><br>$tin<br><br>"; } } } ?> </html>I have no errors, everything works great! It's just I'm not sure how to display them the way I want them. Right now they are displayed like this: IMAGE IMAGE IMAGE IMAGE Any help is greatly appreciated, thank you! Morning I have a table with many rows. Some of these rows have the same id number. I'm wondering how I print all the rows with the like id like so programing,design,help. My fucntion is below. function getPostTags($postid){ $sql = mysql_query("SELECT tag FROM tags WHERE id=$postid") or die(mysql_error()); if (mysql_num_rows($e)){ extract(mysql_fetch_array($sql)); $tags[$postid]=array(); $tags[$postid]['tag']; } return $tags; } So if I do this <?php print $tags; ?> It only prints out one result from my table. What do I have to do it get it to print all row field values from the table with a comma. Right now the only way I can do this is instead of printing "$tags" (which only gives me one of the many values) I query the database again and do a while statement with $row = mysql_fetch_array. This isn't the right way to do it. Can someone help or give me some pointers? Thanks for the help. I can't seem to get the math right! I have a function, pulling 13 states (canadian provinces) from the database and I can't seem to get them all to show in 5 columns. Where am I doing this wrong. The code below only shows 7 of 13... I just can't seem to get where I am off! PHP CODE: function map_showCA() { global $db, $tpl; // ShowLocalResources $sSQL = "SELECT * FROM states_canada ORDER BY state;"; $db->query($sSQL); $next_record = $db->next_record(); while ($next_record) { $state_id = $db->f("id"); $state = $db->f("state"); $statename = $db->f("statename"); $statename_html = $db->f("statename_html"); $next_record = $db->next_record(); if (!USE_SEO_LINKS) { $statename_html = $state_id; } $vendors_states[] = array("name" => $statename, "id" => $state_id, "state_html" => $statename_html); } $vendors_states_col = array_chunk($vendors_states, 5, true); $loop = (int)(count($vendors_states) / 5); if(count($vendors_states) % 5 > 0) $loop++; $j = 0; for($i = 0; $i < $loop; $i++) { $parameters = 'http://'.$vendors_states_col[0][$j]["state_html"].'.ilocalize.com'; // $first_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("first_column_link", $parameters); $tpl->set_var("first_column", tohtml($vendors_states_col[0][$j]["name"])); $parameters = 'http://'.$vendors_states_col[1][$j+6]["state_html"].'.ilocalize.com'; // $second_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("second_column_link", $parameters); $tpl->set_var("second_column", tohtml($vendors_states_col[1][$j+6]["name"])); $parameters = 'http://'.$vendors_states_col[2][$j+12]["state_html"].'.ilocalize.com'; // $threeth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("threeth_column_link", $parameters); $tpl->set_var("threeth_column", tohtml($vendors_states_col[2][$j+12]["name"])); $parameters = 'http://'.$vendors_states_col[3][$j+18]["state_html"].'.ilocalize.com'; // $fourth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fourth_column_link", $parameters); $tpl->set_var("fourth_column", tohtml($vendors_states_col[3][$j+18]["name"])); $parameters = 'http://'.$vendors_states_col[4][$j+24]["state_html"].'.ilocalize.com'; // $fifth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fifth_column_link", $parameters); $tpl->set_var("fifth_column", tohtml($vendors_states_col[4][$j+24]["name"])); $tpl->parse("ShowLocalResourcesCA", true); $j++; } } HTML CODE: Code: [Select] <table border="0" cellpadding="1" cellspacing="1" class="description_text2" style="padding-bottom:6px;" width="100%" id="dashed_box_gray"> <!--BeginShowLocalResourcesCA--> <tr> <td width="110" align="left" style="padding-left:6px; padding:6px;"><a href="{first_column_link}" class="user_blue_14px">{first_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{second_column_link}" class="user_blue_14px">{second_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{threeth_column_link}" class="user_blue_14px">{threeth_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{fourth_column_link}" class="user_blue_14px">{fourth_column}</a></td> <td width="108" align="left" style="padding-right:6px; padding:6px;"><a href="{fifth_column_link}" class="user_blue_14px">{fifth_column}</a></td> </tr> <!--EndShowLocalResourcesCA--> </table> i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks Hi, I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine. What I want to do is to have a piece of text that reads: (insert pre release amount of signer upperers here) have signed up. Will you? I'm guessing that the amount of rows on the table, would end up being the number. How do I do this? Thanks, Jack |