jimmyelewis Posted March 23, 2006 Share Posted March 23, 2006 What I'm trying to do is list some infomation from mysql into a 3 column table. Here's what I have. [code] echo '<div class="title">' . $row['cat_name'] . '</div>'; $query2 = 'SELECT * FROM admin_tools ORDER BY tool_num ASC'; if($r=mysql_query($query2)) { echo '<table>'; while ($row2 = mysql_fetch_array($r)) { echo '<tr>'; $count=0; while ($count<3){ echo '<td>'; if($row2['tool_icon']){$a='<a href="' . $row2['tool_link'] . '"><img src="' . $row2['tool_icon'] . '" border="0" /> </a>';} else {$a=' ';} echo $a . '<a href="' . $row2['tool_link'] . '"><br />' . $row2['tool_name'] . '</a><br /></td>'; $count++; } echo '</tr>'; } echo '</table'; }[/code]Instead of printing each database entry into a new table cell until it reaches 3 and going to the next table row. It prints the each database entry on a new row and mirrows that column to the next 2. What have I written wrong in my code. Quote Link to comment https://forums.phpfreaks.com/topic/5596-listing-information-from-a-database/ Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 $count is always going to be zero according to your code.[code]echo '<div class="title">' . $row['cat_name'] . '</div>'; $query2 = 'SELECT * FROM admin_tools ORDER BY tool_num ASC'; if($r=mysql_query($query2)) { echo '<table>'; $count = 0; while ($row2 = mysql_fetch_array($r)) { if($count == 0) { echo '<tr>'; } echo '<td>'; if($row2['tool_icon']){$a='<a href="' . $row2['tool_link'] . '"><img src="' . $row2['tool_icon'] . '" border="0" /> </a>';} else {$a=' ';} echo $a . '<a href="' . $row2['tool_link'] . '"><br />' . $row2['tool_name'] . '</a><br /></td>'; if(++$count == 3) { echo '</tr>'; $count = 0; } } echo '</table'; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5596-listing-information-from-a-database/#findComment-19964 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.