I have a while loop that runs through a table collecting all rows that relate to a search term. The problem is there are multiple rows in my database that contain the exact same information so when the while loop runs through it will post duplicated information. I’m trying to find a way to prevent the while loop from showing the duplicated the situation. I was thinking of running an if statement around the echoed variable but I’m not sure what I would check to prevent duplicated information from showing. Here is the code below.
$search = mysql_query("SELECT `primary_id`, `person_requested`, `likes` FROM
`requests` WHERE `person_requested` LIKE '%$search_term%'");
while ($results_row = mysql_fetch_assoc($search))
{
$persons = $results_row['person_requested'];
echo $persons;
}
Use
DISTINCTin your query to return distinct records: