I got a simple line of code, that fetch the sequel database and populate a category list, these category strings come by a product table, so many product row produce duplicate category entries.
$cat_result = $mysqli -> query("SELECT * FROM products");
while ($cat_row = mysqli_fetch_array($cat_result, MYSQL_NUM)) {
if($cat_row['4'] != NULL) {
print '<li><a href="/category/'. $cat_row['4'] .'">'. $cat_row['4'] .'</a></li>';
}
}
The current output is like this:
- Category1
- Category1
- Category2
- Category2
So how I can suppress duplicate entry and got something like this?
- Category1
- Category2
Thanks for your help!
$cat_result = $mysqli -> query("SELECT DISTINCT(name) FROM products"); or $cat_result = $mysqli -> query("SELECT * FROM products GROUP BY name");SELECT DISTINCT WhatEverTheColumnIsCalled FROM productsspecially as you only use one column, dont retrieve more than you use and you will find that it run quicker as wellSELECT DISTINCT col1, col2 FROM TABLEas per dev.mysql.com/doc/refman/5.7/en/distinct-optimization.html - come stai?