I have setup an additional table named price_cats that I want to use strictly to help me with navigation.
I've imported 3 columns of categories and subcategories under the columns main, sec, and third. I use the following script in header.php to display my main categories:
<?php
$result = mysql_query('SELECT DISTINCT main from price_cats WHERE main <>"" ORDER BY main');
while($row = mysql_fetch_array( $result )) {
$cats = $row['main'];
print "<li>";
print "<a href='http://www.mysite.com/shop/tags/$cats/'>".$cats."</a>";
print "</li>";
}
?>
This works fine with the following exception.
When using index.php (ie the home page of the tapestry site), I get the following error "Access denied for user 'nobody'@'localhost'". However, the script works fine on all other pages.
Am I doing something wrong here? Should I use foreach instead of while?
Also, I want to be able to display, in a seperate location, all items in columns 'sec' and 'third' where 'main' contains the current selected category.
Hi Mike,
I think what's happening here is that because you have not included any database connection code it is only working on pages where there has already been a database connection made, which on most other pages is probably the case. All you need to do is add the connection code infront of your modification as follows:
$link = mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
mysql_select_db($config_databaseName,$link);
That should bring up the connection and your code should then work fine on index.php. It will continue to work on other pages like this as mysql_connect() reuse an existing link if one has already been made, so it won't cause any problems.
Hope this helps!
Cheers,
David.