11-19-2009, 03:50 PM
|
#1
|
|
|
Subpages not showing up
Hi there,
I have built a menu using CSS, PHP, and javascript. Here is the PHP code below. I am trying to figure out why the sub-sub pages won't show up. The sub category shows up, but not the pages that belong to it.
If I exchange the WHERE subid={$subcat[id]} and make it WHERE subid=1, then it shows up. But otherwise, it isn't recognizing the "id" of the sub category.
PHP Code:
# Connect to the database
// Get the categories $cat_result = mysql_query('SELECT catid, category FROM category;');
// Loop through the categories while ($category = mysql_fetch_assoc($cat_result)) { echo "<li><a href='javascript:blankfunction()'>{$category[category]}</a><ul>";
// Category Pages Loop $page_result = mysql_query("SELECT id, title FROM pages WHERE catid={$category[catid]};"); while ($page = mysql_fetch_assoc($page_result)) { echo "<li><a href='sidepage.php?id={$page[id]}'>{$page[title]}</a></li>"; } //Sub-category loop $subcat_result = mysql_query("SELECT id, catid, subcat FROM subcat WHERE catid={$category[catid]};");
while ($subcat = mysql_fetch_assoc($subcat_result)) { echo "<li><a href='javascript:blankfunction()'>{$subcat[subcat]}</a><ul>"; } // Sub-category page loop $subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid={$subcat[id]};"); while ($subpage = mysql_fetch_assoc($subpage_result)) { echo "<li><a href='sidepage.php?id={$subpage[id]}'>{$subpage[title]}</a></li>";
} echo "</ul></li>"; }
Thanks way in advance!
Last edited by drummer392; 11-20-2009 at 08:35 AM..
|
|
|
11-20-2009, 01:25 AM
|
#2
|
|
|
Try this:
PHP Code:
while ($subcat = mysql_fetch_assoc($subcat_result)) { $subcategory = $subcat['subcat']; echo "<li><a href=\"javascript:blankfunction()\">$subcategory</a><ul>"; } // Sub-category page loop $subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid=" . subcat['id']); while ($subpage = mysql_fetch_assoc($subpage_result)) { $id = $subpage['id']; $title = $subpage['title']; echo "<li><a href=\"sidepage.php?id=$id\">$title</a></li>";
} echo "</ul></li>";
__________________
help = (!(poster.do_my_homework || poster.not_trying )) ? yes : no;
|
|
|
11-20-2009, 08:35 AM
|
#3
|
|
|
hmmm...that didn't change anything.
Let me give you the code for the whole menu. I just gave you the sub-category parts. Maybe that will help:
(updated in 1st post as well)
PHP Code:
# Connect to the database
// Get the categories
$cat_result = mysql_query('SELECT catid, category FROM category;');
// Loop through the categories
while ($category = mysql_fetch_assoc($cat_result))
{
echo "<li><a href='javascript:blankfunction()'>{$category[category]}</a><ul>";
// Category Pages Loop
$page_result = mysql_query("SELECT id, title FROM pages WHERE catid={$category[catid]};");
while ($page = mysql_fetch_assoc($page_result))
{
echo "<li><a href='sidepage.php?id={$page[id]}'>{$page[title]}</a></li>";
}
//Sub-category loop
$subcat_result = mysql_query("SELECT id, catid, subcat FROM subcat WHERE catid={$category[catid]};");
while ($subcat = mysql_fetch_assoc($subcat_result))
{
echo "<li><a href='javascript:blankfunction()'>{$subcat[subcat]}</a><ul>";
}
// Sub-category page loop
$subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid={$subcat[id]};");
while ($subpage = mysql_fetch_assoc($subpage_result))
{
echo "<li><a href='sidepage.php?id={$subpage[id]}'>{$subpage[title]}</a></li>";
}
echo "</ul></li>";
}
|
|
|
11-20-2009, 06:09 PM
|
#5
|
|
|
How? What did you change?
__________________
help = (!(poster.do_my_homework || poster.not_trying )) ? yes : no;
|
|
|
11-20-2009, 06:12 PM
|
#6
|
|
|
Well, I here is the new code.
PHP Code:
while ($subcat = mysql_fetch_assoc($subcat_result))
{
$subcategory = $subcat['subcat'];
$sid = $subcat['id'];
echo "<li><a href=\"javascript:blankfunction()\">$subcategory</a><ul>";
}
// Sub-category page loop
$subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid={$sid}");
while ($subpage = mysql_fetch_assoc($subpage_result))
{
$id = $subpage['id'];
$sptitle = $subpage['title'];
echo "<li><a href=\"sidepage.php?id=$id\">$sptitle</a></li>";
}
echo "</ul></li>";
}
|
|
|
11-20-2009, 06:32 PM
|
#7
|
|
|
I think it was a rogue semicolon here:
$subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid={$subcat[id]};");
__________________
help = (!(poster.do_my_homework || poster.not_trying )) ? yes : no;
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 06:12 PM.
|
|