sc00tz Posted October 13, 2009 Share Posted October 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted October 13, 2009 Share Posted October 13, 2009 Fix your query to return distinct rows instead. You may as well post your query here seeing as you actually asked your question in mysql help. Quote Link to comment Share on other sites More sharing options...
sc00tz Posted October 13, 2009 Author Share Posted October 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
trq Posted October 13, 2009 Share Posted October 13, 2009 SELECT DISTINCT name FROM table WHERE tags LIKE '%$weber%' AND tags LIKE '%$fisher%' AND tags LIKE '%$richmond%'; Quote Link to comment Share on other sites More sharing options...
sc00tz Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks! Solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.