CrazeD Posted June 5, 2007 Share Posted June 5, 2007 I'm trying to code a simple little forum. It seems easy enough, but I'm having trouble displaying the index. Basically, I have to: - Select from forums_cat (to list the category) - Select from forums_topic (to list the topics for that category) - Repeat How do I make it repeat? It lists the categories as a whole block and then stuffs the topics under that as a whole block. I suspect it's because I'm using the while() loop on my query, and if I LIMIT 1 on the category query everything is fine. Code: <?php if (empty ($_GET['action'])) { if (empty ($_GET['cat'])) { print '<table border="1" cellpadding="3" cellspacing="3" class="tutorials_table" width="90%"> <tr> <td width="10%" align="center" bgcolor="#000000"><b>Status</b></td> <td width="66%" align="center" bgcolor="#000000"><b>Forum</b></td> <td width="12%" align="center" bgcolor="#000000"><b>Threads</b></td> <td width="12%" align="center" bgcolor="#000000"><b>Posts</b></td> </tr> </table>'; $sql = "SELECT * FROM forums_cat"; if ($r = mysql_query ($sql)) { while ($row = mysql_fetch_array ($r)) { print ' <table border="1" class="tutorials_table" width="90%"> <tr> <td align="left" bgcolor="#000000"><b><font size="4"<a href="index.php?site=forums&cat='. $row['cat_id'] .'">'. $row['name'] .'</a></font></b></td> </tr> </table> '; $cat_id = $row['cat_id']; } } else { print mysql_error(); } print '<table border="1" class="tutorials_table" width="90%">'; $topicsql = "SELECT * FROM forums_topic WHERE cat_id=$cat_id"; if ($r = mysql_query ($topicsql)) { while ($row = mysql_fetch_array ($r)) { print ' <tr> <td width="10%" align="center" bgcolor="#202020">'. $row['status'] .'</td> <td width="66%" align="left" bgcolor="#202020"><font size="3"><b><a href="index.php?site=forums&cat='. $row['cat_id'] .'&tid='. $row['topic_id'] .'">'. $row['name'] .'</a></b></font><br /> <font size="2">'. $row['description'] .'</font></td> <td width="12%" align="center" bgcolor="#202020">5304</td> <td width="12%" align="center" bgcolor="#202020">30405</td> </tr> '; } } else { print mysql_error(); } print '</table>'; } } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/54258-solved-trying-to-make-a-forum-need-help-with-listing-mysql-info/ Share on other sites More sharing options...
zq29 Posted June 5, 2007 Share Posted June 5, 2007 You're probably finding that it is only displaying the topics for the last category. You need to be running your code that fetches the topics, inside the while() loop that is running through your categories. Quote Link to comment https://forums.phpfreaks.com/topic/54258-solved-trying-to-make-a-forum-need-help-with-listing-mysql-info/#findComment-268262 Share on other sites More sharing options...
CrazeD Posted June 5, 2007 Author Share Posted June 5, 2007 I was going to try that, but I heard it's not good to run a query inside of a query. Quote Link to comment https://forums.phpfreaks.com/topic/54258-solved-trying-to-make-a-forum-need-help-with-listing-mysql-info/#findComment-268264 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.