3motions Posted September 18, 2008 Share Posted September 18, 2008 Hey guys.. I appreciate all of the help you guys have given me in getting this website of mine to work correctly. It's definitely appreciated.. Now, the next question I have for you is I want to pull out products that I have in my MySQL database. But like most of the things I display on my website, I don't want it to show up just in a list that goes straight down. I want to arrange everything that I pull out of the database into a table with 3 columns and however many rows it takes to display everything. So, in simpler terms.. Instead of displaying like this: - Gift Card - Playstation - Pizza - Coffee - Shoes - Clothes I want it to display like this: Gift Card Playstation Pizza Cofee Shoes Clothes Can anyone help me out with this? I've tried searching on Google, but I can't quite get the terminology down right so I can't really find the right code. Thanks! Link to comment https://forums.phpfreaks.com/topic/124878-retrieving-mysql-info-and-putting-it-into-3-columns/ Share on other sites More sharing options...
Barand Posted September 18, 2008 Share Posted September 18, 2008 <?php include 'db.php'; define ("NUMCOLS",3); $res = mysql_query("SELECT col1, col2 FROM mytable"); $count = 0; echo "<TABLE border=1>"; while (list($col1, $col2) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$col1<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row } # end row if not already ended if ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n"; } echo "</TABLE>"; ?> Link to comment https://forums.phpfreaks.com/topic/124878-retrieving-mysql-info-and-putting-it-into-3-columns/#findComment-645239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.