...

View Full Version : PHP Forum Question



Al_90
02-10-2006, 11:37 PM
Me and my friend started to create our own php/mysql forums like phpbb but different, so far its going great but we came across this one error. This is my code


<select name="forum_jump" onchange="jumptoforum">
<option value="0" selected="selected">Select Forum</option>
<?php
$query = mysql_query("SELECT * FROM `cats` ORDER BY `cat_order`");
while ($cats = mysql_fetch_array($query))
{
$title = $cats['cat_title'];
?>
<option value="0">--- <?=$title ?></option>
<?
}
$query2 = mysql_query("SELECT * FROM `forums` WHERE `cat_id` = $cat_id ORDER BY `forum_order` DESC");
while ($forums = mysql_fetch_array($query2)) {
$forum_id = $forums['forum_id'];
$forum_name = stripslashes($forums['forum_name']);
?>
<option value="<?=$forum_id ?>">|- <?=$forum_name ?></option>
<?
}
?>
</select>

and when i open the page it only shows the categories in the select box, not the fourms, any help would be appreciated

marek_mar
02-11-2006, 12:55 AM
Could you show us what the code outputs and what it should output?
Where is $cat_id?

WHERE `cat_id` = $cat_id
You are looping for the results but you select only a specific ID.

Al_90
02-11-2006, 01:58 AM
heres the outputs
http://img136.imageshack.us/img136/8674/show3pj.png
about the $cat_id im going back into my file to see if its totally left out or i jus forgot to write it in my original post

Al_90
02-11-2006, 02:14 AM
ok i went back and $cat_id was not there, i went ahead and added it, but it still doesn't work and this is what i got
http://img156.imageshack.us/img156/3671/show7et.png
it should have 2 categories and 2 forums under them, but i get the 2 categories but only 1 forum under 1 category

marek_mar
02-11-2006, 02:33 AM
Well the $cat_id is somewhat important... if you really have the rows with the correct category id, then the problem is most likely what value $cat_id holds. I think it should hold the value og $cats['id'] (if "id" is the right name).

Al_90
02-11-2006, 02:41 AM
i know and right now my code is:


<select name="forum_jump" onchange="jumptoforum">
<option value="0" selected="selected">Select Forum</option>
<?php
$query = mysql_query("SELECT * FROM `cats` ORDER BY `cat_order`");
while ($cats = mysql_fetch_array($query))
{
$title = $cats['cat_title'];
$cat_id = $cats['cat_id'];
?>
<option value="0">--- <?=$title ?></option>
<?
}
$query2 = mysql_query("SELECT * FROM `forums` WHERE `cat_id` = $cat_id ORDER BY `forum_order` DESC");
while ($forums = mysql_fetch_array($query2)) {
$forum_id = $forums['forum_id'];
$forum_name = stripslashes($forums['forum_name']);
?>
<option value="<?=$forum_id ?>">|- <?=$forum_name ?></option>
<?
}
?>
</select>

and it only is displaying the 2 fcategories and one forum instead of 2 categories and the 2 forums under each category

marek_mar
02-11-2006, 03:11 AM
By the way the code is indented I thought that thesecond while loop is inside the first one... That explains why the first category has no forums at all. You could generate that jumpbox like that but you should cache the result.

Al_90
02-11-2006, 10:32 PM
so should i put the forum while loop inside the category while loop?

marek_mar
02-11-2006, 10:45 PM
Well I assume that the `cat_id` in the `forums` table holds the category of that forum... so if you're selecting forums with a specific `cat_id` you'd have to do it for every category.
There are ways of storing data which will require only one query to get all data (MPTT for instance).

Al_90
02-11-2006, 11:05 PM
can you give me an example of a script that will show all the forums under each category?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum