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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.