Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not show duplicate rows

Tags:

php

mysql

I am trying to query a MySQL database so I can build a select box. But there are duplicate values being returned. Is there anyway to only show one of each value. Below is my query but when I echo the results it show every row. I need only to show one of each value.

$query = "SELECT name FROM ImageInfo";

$db = new connection();

$result = $db->query($query);


while($info = mysql_fetch_array($result)){
    $content[] = $info;
    }

    $result=array();
    $count = count($content);

 for ($x=0;$x<$count;++$x)
 {
    $result[$x][] = $content[$x]['name'];
 }

echo json_encode($result);

and if names row was as follows"

name
Mike
Julia
Julia
Julia
Mike
Ben
Tom
Ben

when the data echos I am trying to only show

Mike
Julia
Ben
Tom
like image 923
Denoteone Avatar asked Feb 06 '26 15:02

Denoteone


1 Answers

$query = "SELECT DISTINCT name FROM ImageInfo";

That should do the trick. :)

like image 150
nderjung Avatar answered Feb 09 '26 03:02

nderjung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!