Jump to content

[SOLVED] Stopping a while loop for certain values...


sc00tz

Recommended Posts

If you have a simple while loop set up to return a MySQL search result, is there a way to have the loop NOT echo repeat values for the queried variable?  What I mean is, say you have this code:

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

    echo "$row['name'] <br>" .

}

 

and the $result from the query includes 'name' values "Bob," "Jim," "Bob," "Bob," "Greg," "Bob," "Rick," and "Jim."

 

I don't want it to display:

Bob

Jim

Bob

Bob

Greg

Bob

Rick

Jim

 

I just want it to display:

Bob

Jim

Greg

Rick

 

 

Is there a way to do this?

good point, my fault.  here's the code:

 

$searchresult = mysql_query("SELECT name FROM table WHERE tags LIKE '%$weber%' AND tags LIKE '%$fisher%' AND tags LIKE '%$richmond%'");

 

while($row = mysql_fetch_array($searchresult))

{

echo "<tr><td>";

  echo $row['name'];

  echo "</td></tr>";

 

 

So it's something I need to change in the query, not in the while loop?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.