Welcome to WebmasterWorld Guest from 54.162.167.40

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Displaying pages under categories

connecting foreign keys to the parent keys

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

WebmasterWorld Senior Member 10+ Year Member



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
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";
1:23 pm on May 23, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month