homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Displaying pages under categories
connecting foreign keys to the parent keys
whatson




msg:4456798
 3:26 am on May 23, 2012 (gmt 0)

I should explain what I am trying to do:
I want the navigation menu to display the pages that belong to a category on the that category page, and on a page that is in that category, the other pages must also show that also belong to that category.
Does that make sense? Anyway, here is my code, which might help explain what I am trying to do, I keep getting an error, and the pages do not show either.

<?php
$qry = 'SELECT * FROM categories WHERE hide = 1 ORDER BY sort';
$result = mysql_query($qry);
while($row = mysql_fetch_array($result)) {
$dbCatName = $row['name'];
$dbCatId = $row['id'];
if ($_GET['id']==$dbCatId) {
echo '> <a href="category.php?id="' . $dbCatId . '">' . $dbCatName . '</a><br>';
$pageQry = 'SELECT * FROM pages WHERE hide=1 AND category=$dbCatId ORDER BY sort';
$pageResult = mysql_query($pageQry);
while($pageRow = mysql_fetch_array($pageResult)) {
echo '<a href="page.php?id="' . $pageRow['id'] . '">' . $pageRow['name'] . '</a><br>';
}
} else {
echo '<a href="category.php?id="' . $dbCatId . '">' . $dbCatName . '</a><br>';
}
}

?>

The error is:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\cms-tutorial\templates\template-pages.php on line 32

 

CoursesWeb




msg:4456913
 12:10 pm on May 23, 2012 (gmt 0)

Hi
That error is because the mysql returns an error.
If you want to add variable directly into a string, put the string between double quotes.
So, the Select should be:
$qry = "SELECT * FROM pages WHERE hide=1 AND category=$dbCatId ORDER BY sort";
whatson




msg:4456938
 1:23 pm on May 23, 2012 (gmt 0)

Yeah, I realised that, but it still doesnt do what I want.
How can I show pages that belong to a category in the navigation, for each category, and only showing the pages of that category on the category page?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved