Forum Moderators: coopster
For my websiteI use php and Mysql to create dynamic pages.
What I want to do is create a dynamic navigation menu where (among other things) all the categories are shown. Categories come and go, so making a navigation menu that keeps track of this would save a lot of time.
What I need is a query that outputs all the categories, but every unique category just one time. Its simple to output the entire list, but it needs to be limites so that every output is unique.
I've looked around but cant seem to find what I need...
(edit: all the different categories are saved in product.categorie)
[edited by: Joppiesaus at 10:42 am (utc) on Jan. 30, 2009]
$query_Index = "SELECT distinct product.categorie FROM product ORDER BY product.categorie ASC";
$result = mysql_query($query_Index) or die("Couldnt' execute query.");
while ($newArray = mysql_fetch_array($result)){
$cat = $newArray['product.categorie'];
print "$cat";
}
Should give you a start
The code doesnt seem to work yet. I tried it on different pages (some where database connections wehere already made and other dynamic stuff already works and also on different pages. I also tryed different variables, but every time nothing is echoed (or is it printed?).
What can I do to figure out the mistake I made?
print "$query";
like this
$result = mysql_query($query_Index) or die("Couldnt' execute query.");
print "$query";
while ($newArray = mysql_fetch_array($result)){
and see if anything prints, if not try running the query
SELECT distinct product.categorie FROM product ORDER BY product.categorie ASC
from within phpmyadmin and see what returns.
I am not a pro by any means, most of my efforts fail first time around (lazy to read first) to eliminate most problems cut down your query to just
SELECT distinct product.categorie FROM product
from the original code
ASC
should be
'ASC'
HTH