Jump to content

[SOLVED] Trying to make a forum, need help with listing MySQL info


Recommended Posts

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.

 

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.