Forum Moderators: open

Message Too Old, No Replies

Displaying without repeats mysql/php

         

Jimmyco

6:08 am on Feb 24, 2007 (gmt 0)

10+ Year Member



I am building an widget store. Each item belongs to a category. I have the query go through all the records and pulls all the categories, this ensures the category list only gives results for categories that have items in them. This is how it prints:

BOY
BOY
GIRL
GIRL
XEON

The problem is that I want it to ignore the repeats, therefore giving me this:

BOY
GIRL
XEON

I am using the following php code to pull them all:

<?
$query="SELECT * FROM product WHERE status='show' ORDER BY cat ASC LIMIT 0,1";
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$cat=mysql_result($result,$i,"cat");

echo "$cat <BR><BR>";

$i++;
}
?>

Any help or ideas would be great, I hope I am clear on the problem I am having.

syber

6:12 am on Feb 24, 2007 (gmt 0)

10+ Year Member



SELECT DISTINCT cat FROM product WHERE status='show' ORDER BY cat ASC LIMIT 0,1

Jimmyco

6:20 am on Feb 24, 2007 (gmt 0)

10+ Year Member



Hey thanks! That worked like a charm.