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!

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
}

Member Avatar for diafol

Use

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
Thanks

the select distinct worked, thanks!

Looks like you need to mark the thread solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.