LemonInflux Posted September 29, 2007 Share Posted September 29, 2007 <?php $sql = 'SELECT * FROM `categories`'; $sqlresult = mysql_query($sql); while ($row = mysql_fetch_assoc($sqlresult)) { echo '<p><table width="100%" border="1" cellpadding="5" cellspacing="0"><tr><td height="37" colspan="2" background="Images/main_bg.png">'. $row['cat_name'] .'</td>'; $sql = 'SELECT * FROM `forums` where cat_id = "'. $row['cat_id'] .'"'; $sqlresult = mysql_query($sql); while ($row2 = mysql_fetch_assoc($sqlresult)) { echo '<tr><tr><td width="492" height="37" background="Images/main_bg.png">'. $row2['forum_name'] .'<td height="39" background="Images/lower_bg.png">'. $row2['forum_desc'] .'</td></tr>'; } } echo '</table></p>'; ?> Basically, it lists each forum under their category's header. However, at the moment, it is only listing the first category, not the others. So what's wrong with the code? PS: To see a basic example, go here: http://reflexprojects.net/forumbuild/ Quote Link to comment https://forums.phpfreaks.com/topic/71164-solved-more-mysql/ Share on other sites More sharing options...
BlueSkyIS Posted September 29, 2007 Share Posted September 29, 2007 don't loop over $sqlresult and set $sqlresult within the loop. you're 'erasing' the first recordset in the loop. while ($row = mysql_fetch_assoc($sqlresult)) { echo '<p><table width="100%" border="1" cellpadding="5" cellspacing="0"><tr><td height="37" colspan="2" background="Images/main_bg.png">'. $row['cat_name'] .'</td>'; $sql2 = 'SELECT * FROM `forums` where cat_id = "'. $row['cat_id'] .'"'; $sqlresult2 = mysql_query($sql2); while ($row2 = mysql_fetch_assoc($sqlresult2)) { echo '<tr><tr><td width="492" height="37" background="Images/main_bg.png">'. $row2['forum_name'] .'<td height="39" background="Images/lower_bg.png">'. $row2['forum_desc'] .'</td></tr>'; } } [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/71164-solved-more-mysql/#findComment-357928 Share on other sites More sharing options...
LemonInflux Posted September 29, 2007 Author Share Posted September 29, 2007 Erm...I added that, and now the category/forum space has dissapeared. Quote Link to comment https://forums.phpfreaks.com/topic/71164-solved-more-mysql/#findComment-357929 Share on other sites More sharing options...
LemonInflux Posted September 29, 2007 Author Share Posted September 29, 2007 Wait, I thought about it, and just took mine and put '2' after sql and sqlresult. Works, topic solved. Quote Link to comment https://forums.phpfreaks.com/topic/71164-solved-more-mysql/#findComment-357930 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.