Jump to content

Recommended Posts

<?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/

Link to comment
https://forums.phpfreaks.com/topic/71164-solved-more-mysql/
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/71164-solved-more-mysql/#findComment-357928
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.