fluxem Posted June 11, 2007 Share Posted June 11, 2007 I realize this probably pretty basic but nonetheless I need a point in the right direction .. heres what I got: I currently have it to where the user can input data and it is stored in a mysql db.. I am having problems with the output portion and it being formatted the way I would like it. I want for it to print the all the data results inside of html tables... 5 across (columns) and 2 down (rows) so a total of ten records are printed out. After 10 I want it to generate a second page with the next 10 records.. these records will all be sorted by date.. here is a screen shot.. http://fluxar.com/images/star.jpg here is the code I currently have to print my results.. <?php include ('connect/index.php') ?> <?php mysql_connect(localhost, $username, $password); @mysql_select_db($database) or die("Unable to select database"); $query = "SELECT * FROM saleitems"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); echo "<center>Database Output</center><br><br>"; ?> <table border="1" cellspacing="2" cellpadding="2" align="center"> <tr> <?php $i=0; while ($i < $num){ $image = mysql_result($result, $i, "image"); $name = mysql_result($result, $i, "name"); $classification = mysql_result($result, $i, "classification"); $percentoff = mysql_result($result, $i, "percentoff"); $dateadded = mysql_result($result, $i, "dateadded"); ?> <td><?php echo "<img src=\"$image\"><br>$name<br>$classification<br>$percentoff<br>"; ?></td> <?php $i++; } echo "</tr></table>"; ?> any help on this would be greatly appreciated! thanks Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/ Share on other sites More sharing options...
simcoweb Posted June 11, 2007 Share Posted June 11, 2007 You could use something like this: // display results $totalColumns = 5; $i = 1; echo "<table border='0' cellpadding='2'>"; while ($row = mysql_fetch_array($results)){ if ($i == 1) echo "<tr>"; echo "<td>"; echo "place your database row calls in here"; echo "</td>"; if ($i == $totalColumns) { echo "</tr>"; $i = 0; } $i++; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-272631 Share on other sites More sharing options...
fluxem Posted June 11, 2007 Author Share Posted June 11, 2007 Him Simcoweb,, thank you for your reply! I am getting this error.. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/fluxar/public_html/clients/starfurniture/sale-items3.php on line 20 here is my updated code: <?php include ('connect/index.php') ?> <?php mysql_connect(localhost, $username, $password); @mysql_select_db($database) or die("Unable to select database"); $query = "SELECT * FROM saleitems"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); echo "<center>Database Output</center><br><br>"; ?> <?php // display results $totalColumns = 5; $i = 1; echo "<table border='0' cellpadding='2'>"; while ($row = mysql_fetch_array($results)){ if ($i == 1) echo "<tr>"; echo "<td>"; echo "<img src=\"$image\"><br>$name<br>$classification<br>$percentoff<br>"; echo "</td>"; if ($i == $totalColumns) { echo "</tr>"; $i = 0; } $i++; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-272704 Share on other sites More sharing options...
suma237 Posted June 12, 2007 Share Posted June 12, 2007 Hi, Use mysql_close() function at the end try.. Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-272974 Share on other sites More sharing options...
fluxem Posted June 12, 2007 Author Share Posted June 12, 2007 Hi Suma I put that at the end and I still get the same error.. Here is my current code: <?php include ('connect/index.php') ?> <?php mysql_connect(localhost, $username, $password); @mysql_select_db($database) or die("Unable to select database"); $query = "SELECT * FROM saleitems"; $result = mysql_query($query); $num = mysql_numrows($result); echo "<center>Database Output</center><br><br>"; ?> <?php // display results $totalColumns = 5; $i = 1; echo "<table border='0' cellpadding='2'>"; while ($row = mysql_fetch_array($results)){ if ($i == 1) echo "<tr>"; echo "<td>"; echo "<img src=\"$image\"><br>$name<br>$classification<br>$percentoff<br>"; echo "</td>"; if ($i == $totalColumns) { echo "</tr>"; $i = 0; } $i++; } echo "</table>"; ?> <?php mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-273450 Share on other sites More sharing options...
simcoweb Posted June 12, 2007 Share Posted June 12, 2007 change: while ($row = mysql_fetch_array($results)) { to: while ($row = mysql_fetch_array($result)){ without the 's' on $result Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-273460 Share on other sites More sharing options...
fluxem Posted June 14, 2007 Author Share Posted June 14, 2007 works great, thank you very much! Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-274304 Share on other sites More sharing options...
simcoweb Posted June 14, 2007 Share Posted June 14, 2007 No problemo Link to comment https://forums.phpfreaks.com/topic/55147-loop-with-html-tables/#findComment-274310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.