Do not show duplicate rows
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();
$c开发者_C百科ount = 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
$query = "SELECT DISTINCT name FROM ImageInfo";
That should do the trick. :)
精彩评论