Canman2005 Posted March 6, 2006 Share Posted March 6, 2006 Hi allI have a php result page which currently displays results one after each other, likeresult 1result 2result 3result 4I use a very simple php query, which is[code]<?session_start();include ("db.php");$sql ="SELECT * FROM files";$result = @mysql_query($sql,$connection) or die(mysql_error());?>[/code]followed by the code for results[code]<?while ($rows = mysql_fetch_array($result)) {?><? print "$rows[name]"; ?><br><?}?>[/code]How can I get results to appear in a 4 column wide table, the code for the table would look like[code]<table> <tr> <td>result 1</td> <td>result 2 </td> <td>result 3 </td> <td>result 4 </td> </tr> <tr> <td>result 5 </td> <td>result 6 </td> <td>result 7 </td> <td>result 8 </td> </tr></table>[/code]rather than appearing one after each other? Is that easy?Loads of thanks in advanceDave Link to comment https://forums.phpfreaks.com/topic/4208-4-column-results/ Share on other sites More sharing options...
XenoPhage Posted March 6, 2006 Share Posted March 6, 2006 Use a counter...[code]$counter = 0;while ($rows = mysql_fetch_array($result)) { if ($counter == 4) { $counter = 0; print "</tr><tr>\n"; } print "<td>" . $rows[0] . "</td>\n"; $counter++;}[/code]Note : You need to adjust accordingly if you intersperse php with html.. (Personally, I use smarty templates) Link to comment https://forums.phpfreaks.com/topic/4208-4-column-results/#findComment-14635 Share on other sites More sharing options...
shocker-z Posted March 6, 2006 Share Posted March 6, 2006 [code]<?session_start();include ("db.php");$sql ="SELECT * FROM files";$result = @mysql_query($sql,$connection) or die(mysql_error());?><table><?$i=1;while ($rows = mysql_fetch_array($result)) {} if ($i=5) { echo("</tr>"); $i=1;}if ($i=1) { echo("<tr>");}echo("<td>$row[name]</td>");$i++;?></table><br><?}?>[/code]I think that should do the job mate :) Link to comment https://forums.phpfreaks.com/topic/4208-4-column-results/#findComment-14639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.