Modernvox Posted August 25, 2010 Share Posted August 25, 2010 Hi Guys! Trying to display data in 3 rows horizontally and 25 vertiacally // 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/ Share on other sites More sharing options...
wildteen88 Posted August 25, 2010 Share Posted August 25, 2010 Multi-column results Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103660 Share on other sites More sharing options...
Modernvox Posted August 25, 2010 Author Share Posted August 25, 2010 Did I mention I Only been programming in PHP for a bout a year? Where do I insert this Modulus Operator in my code? <?php $cols = 0; echo "<table><tr>"; while ($cols < 20) { echo ($cols % 3 == 0)? "</tr><tr>" : ""; echo "<td>$cols</td>"; $cols++; } echo "</tr></table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103676 Share on other sites More sharing options...
monkeytooth Posted August 25, 2010 Share Posted August 25, 2010 Where ever within the page you would like the results to display. All depends on the design of the page Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103677 Share on other sites More sharing options...
Modernvox Posted August 25, 2010 Author Share Posted August 25, 2010 Where ever within the page you would like the results to display. All depends on the design of the page Understood, but what i meant was how do I tie the new code with my current code? So where does this $cols = 0; echo "<table><tr>"; while ($cols < 20) { echo ($cols % 3 == 0)? "</tr><tr>" : ""; echo "<td>$cols</td>"; $cols++; } echo "</tr></table>"; go to make this work... 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103679 Share on other sites More sharing options...
sasa Posted August 25, 2010 Share Posted August 25, 2010 try <?php // 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>", str_repeat("<td>Bidders</td>",3), "</tr>\n"; // keeps getting the next row until there are no more to get $i=0; while($row = mysql_fetch_array( $result )) { if ($i == 0) echo "<tr>"; $i++; // Print out the contents of each row into a table echo "<td>"; echo"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</font>"; echo "</td>"; if ($i == 3){ echo "</tr>\n"; $i=0; } } if ($i>0){ while ($i++ <3) echo '<td> </td>'; echo "</tr>\n"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103686 Share on other sites More sharing options...
Modernvox Posted August 25, 2010 Author Share Posted August 25, 2010 try <?php // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(biddersId)'] ." bidders logged."; echo "<br />"; } Wow... Thanks. Works great! It's doing 9 rows down , but it works. Thanks again! $query = "SELECT * FROM bidders ORDER BY biddersId"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr>", str_repeat("<td>Bidders</td>",3), "</tr>\n"; // keeps getting the next row until there are no more to get $i=0; while($row = mysql_fetch_array( $result )) { if ($i == 0) echo "<tr>"; $i++; // Print out the contents of each row into a table echo "<td>"; echo"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</font>"; echo "</td>"; if ($i == 3){ echo "</tr>\n"; $i=0; } } if ($i>0){ while ($i++ <3) echo '<td> </td>'; echo "</tr>\n"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/211719-how-to-display-an-array-horizontally-in-a-set-number-of-rows/#findComment-1103690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.