ubh
12-05-2008, 04:26 AM
Hi got a database filled with products. They are sorted by a product category.
category1, product1
category1, product2
category1, product3
category2, product1
category2, product2
category2, product3
Now all I want to do is loop through the records and echo out all product category's there are. Problem is that it echo's out all listed category's there are in the database instead of all unique category's.... That make sence?
Anyone know how I would set up my query to do such a thing? Here is my current query and mysql_fetch_array.
<?php
include("db_cnt.php");
$result = mysql_query("SELECT * FROM site_products")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$product_category = $row['product_category'];
echo "<option value='" . $product_category . "' >";
echo $product_category;
echo "</option>";
}
?>
category1, product1
category1, product2
category1, product3
category2, product1
category2, product2
category2, product3
Now all I want to do is loop through the records and echo out all product category's there are. Problem is that it echo's out all listed category's there are in the database instead of all unique category's.... That make sence?
Anyone know how I would set up my query to do such a thing? Here is my current query and mysql_fetch_array.
<?php
include("db_cnt.php");
$result = mysql_query("SELECT * FROM site_products")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$product_category = $row['product_category'];
echo "<option value='" . $product_category . "' >";
echo $product_category;
echo "</option>";
}
?>