Getting category of a table in Mysql

Asked

Viewed 67 times

0

Staff 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 he brings me like this:

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

Like leaving only one Category title and not duplicated like this one. Ever since I thank!

1 answer

1


Only necessary to group by field categoria

SQL Search

$consulta = mysql_query('select categoria from produtos group by categoria order by categoria');
  • Thanks Marlon worked perfectly :)

  • @kidFirst, mark the answer as correct ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.