I'm trying to simply display some data from my database, but without duplicates, I'm working with the following code:

$query = mysql_query("SELECT answers FROM users");
$rows = mysql_num_rows($query);

for ($j = 0 ; $j <= $rows ; ++$j) 
$row = mysql_fetch_row($result);
echo $row[0]."<br>";

This works perfectly for just displaying the information from my database. but when trying to only display unique values, it isn't working...

I've tried:

$query = array_unique($query);


$row = array_unique($row);

and several others, yet nothing is working. :confused:
Please let me know of a solution if you know of one, thanks!

try thing if still problem then sent you error thanks

array_unique :-

$query = mysql_query("SELECT answers FROM users");


$row = mysql_fetch_array($result);
foreach($answerArrDistinct as $answer)
echo $answer; //show all unique answers

Member Avatar


select distinct answers from users

but this time use array_unique
because it will good to learn how to use "array_unique" because if query will be so complex with join then it will help you

the select distinct worked, thanks!

Looks like you need to mark the thread solved