0

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);

and

$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!

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by cwarn23
0

try thing if still problem then sent you error thanks

array_unique :-
______________________________________________________________________

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

$result=mysql_query($query);

while($row=mysql_fetch_array($result))
{
$row = mysql_fetch_array($result);
answerArr[]=$row[0]."<br>";
}
$answerArrDistinct[]=array_unique($answerArr);
foreach($answerArrDistinct as $answer)
{
echo $answer; //show all unique answers
}

0

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
Thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.