|
Posted by Chris on 07/06/06 19:02
I have a navigation bar that is populated from a MySQL database
which works nicely for displaying categories & subcategories.
However, I want the subcategories to be links to pages in other file
folders, which then are displayed in the content portion of the page.
I can't seem to set up a variable to hold the doc name page plus and
extension such as .html. This is the current set up with no
specific document defined (only a subcategory):
--SNIP--
<p>Categories:</p>
<?php
mysql_select_db($database_website, $website);
$query_categories = "SELECT * FROM cat ORDER BY catID ASC";
$categories = mysql_query($query_categories, $website) or die
(mysql_error());
$row_categories = mysql_fetch_assoc($categories);
$totalRows_categories = mysql_num_rows($categories);
$pageid= ""
?>
<ul id="menu">
<?php do { ?>
<li><?php echo $row_categories['catName']; ?>
<?php
mysql_select_db($database_website, $website);
$query_subcat = "SELECT * FROM subcat ORDER BY subcatID ASC";
$subcat = mysql_query($query_subcat, $website) or die(mysql_error());
$row_subcat = mysql_fetch_assoc($subcat);
$totalRows_subcat = mysql_num_rows($subcat);
?>
<ol>
<?php do{
if ($row_subcat['catID']==$row_categories['catID']) {?>
<li><a href="<?php echo $row_subcat['subcatName']; ?
>"><?php echo $row_subcat['subcatName']; ?> </a></li>
<?php }
}
while ($row_subcat = mysql_fetch_assoc($subcat)); ?
>
</ol>
</li>
<?php } while ($row_categories = mysql_fetch_assoc($categories)); ?>
</ul>
--SNIP--
When I try to assign a variable such as $pageid to be used in the <a
href="link"> it no longer goes through the $row_subcat['subcatName'] array
and just sees the first item in the array.
How I was setting up the variable:
$pageLink = $row_subcat['subcatName'] . ".html";
Then sub it in:
<li><a href="<?php echo $pageLink ?>"><?php echo $row_subcat
['subcatName']; ?> </a></li>
When clicked it should appear in the content section with:
//Set Default Page ($pageLink)
if(!isset($pageLink) || !file_exists($pageLink)) $pageLink= "home.html";
if(file_exists($pageLink))
{
include $pageLink;
}
Any guidance on this?
Thanks,
Chris
[Back to original message]
|