php_b34st Posted September 11, 2006 Share Posted September 11, 2006 Hi I use the following code to retrieve data from mysql an insert it into a table:[code]$query = "SELECT * FROM stats WHERE userID='$user'"; $result = mysql_query($query) or die("Could not query: " . mysql_error());$info = array();$i = 0;while ($row = mysql_fetch_assoc($result)) { $info[$i]['cat'] = $row['cat']; $info[$i]['statB'] = $row['statB']; $i++; }echo '<table align="center" border="0" cellpadding="2" cellspacing="2" class="forumline"> <tr> <th class="cat" height="28" colspan="4"><span class="cattitle">Personal Scores For ' . $user . '</th> </tr> <tr> <th class="titlemedium">Skill</th> <th class="titlemedium">Level</th> </tr>';$i = 0;foreach ($info as $r => $value) { echo ' <tr> <td class="row1"><span class="genmed">' . $info[$r]['cat'] . '</span></td> <td class="row1"><span class="genmed">' . $info[$r]['statB'] . '</td> </tr>'; $i++;}echo '</table></div></div>';[/code]The script works fine but it produces a long narrow table, is there a way that i can limit the rows to 5 and have a table that is more like this:[code]<table> <tr> <td><img src="images/icons/attack.png"></td> <td><img src="images/icons/prayer.png"></td> <td><img src="images/icons/runecraft.png"></td> <td><img src="images/icons/fishing.png"></td> <td><img src="images/icons/farming.png"></td> </tr> <tr> <td><img src="images/icons/strength.png"></td> <td><img src="images/icons/magic.png"></td> <td><img src="images/icons/craft.png"></td> <td><img src="images/icons/cooking.png"></td> <td><img src="images/icons/construction.png"></td> </tr> <tr> <td><img src="images/icons/defense.png"></td> <td><img src="images/icons/agility.png"></td> <td><img src="images/icons/fletching.png"></td> <td><img src="images/icons/firemaking.png"></td> </tr> <tr> <td><img src="images/icons/hp.png"></td> <td><img src="images/icons/herblore.png"></td> <td><img src="images/icons/mining.png"></td> <td><img src="images/icons/woodcutting.png"></td> </tr> <tr> <td><img src="images/icons/range.png"></td> <td><img src="images/icons/thieving.png"></td> <td><img src="images/icons/smithing.png"></td> <td><img src="images/icons/slayer.png"></td> </tr></table>[/code]Thanks in advance Link to comment https://forums.phpfreaks.com/topic/20419-generating-tables-with-php/ Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 [code]<?php$i = 0;foreach ($info as $r => $value) { if ($i == 0) echo "<tr>"; echo '<td class="row1"><span class="genmed">' . $info[$r]['cat'] . '</span></td> <td class="row1"><span class="genmed">' . $info[$r]['statB'] . '</td>'; if (++$i == 5) { $i = 0; echo "</tr>"; }}?>[/code]Try that. Link to comment https://forums.phpfreaks.com/topic/20419-generating-tables-with-php/#findComment-89971 Share on other sites More sharing options...
php_b34st Posted September 11, 2006 Author Share Posted September 11, 2006 That works great thank you Link to comment https://forums.phpfreaks.com/topic/20419-generating-tables-with-php/#findComment-89974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.