Picking category from a table in Mysql

0

Personal I have a product registration table and in it I have categories:

$consulta = mysql_query('select categoria from produtos order by categoria');
 while ($var=mysql_fetch_array($consulta))
    {
        echo "<a href='editar.php?categoria=$var[categoria]'>$var[categoria]</a><br><br>";
    }

The problem is that it brings me like this:

-Bebidas
-Bebidas
-Higiene e Limpeza
-Higiene e Limpeza
-Mercearia
-Padaria e Confeitaria

How to leave only one title of the Category and not duplicate as it is getting. Thank you!

    
asked by anonymous 28.02.2018 / 13:57

1 answer

1

Only grouped by field categoria

Search SQL

$consulta = mysql_query('select categoria from produtos group by categoria order by categoria');
    
28.02.2018 / 14:07