I've got this function to get only distinct values from the db
function get_all_product_data_admin()
{
$query = "SELECT DISTINCT category FROM products ORDER BY product_id AS";
mysql_query("SET NAMES 'utf8'");
$result = mysql_query($query);
if($result == false) //Something is wrong with the query
echo "result non";
if(mysql_num_rows($result) == 0) //No Pages
echo "result 0";
while($row = mysql_fetch_assoc($result)) // MAKES 2D ARRAY FOR DRAWING A LIST
{
$returned_array[] = $row;
}
return $returned_array;
}
And this is the html. I use switch
, so the English values would appear as their Hebrew translation.
$menu = get_all_product_data_admin();
foreach($menu as $key=>$val) {
switch($val['category'])
{
case "bread": $catt = "לחמים"; break;
case "buns": $catt = "לחמניות"; break;
case "bake": $catt = "מאפים"; break;
case "cake": $catt = "עוגות"; break;
case "cookies": $catt = "עוגיות"; break;
case "dessert": $catt= "קינוחים אישיים"; break;
case "pita": $catt = "פיתות"; break;
case "friday": $catt = "חלות יום ו"; break;
case "baget": $catt = "באגטים"; break;
case "jabeta": $catt = "ג'בטות"; break;
case "nogloten": $catt = "ללא גלוטן"; break;
case "holiday": $catt = "מוצרי חגים"; break;
case "special": $catt = "מיוחדים"; break;
}
echo '
<a style="float:right;" href="add_product.php?cname='.$val['category'].'">
'.$catt.'
</a>
';
}
Still I've got values coming back duplicated. Anyone ?