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? Link to comment https://forums.phpfreaks.com/topic/177502-solved-stopping-a-while-loop-for-certain-values/ 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. Link to comment https://forums.phpfreaks.com/topic/177502-solved-stopping-a-while-loop-for-certain-values/#findComment-935897 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? Link to comment https://forums.phpfreaks.com/topic/177502-solved-stopping-a-while-loop-for-certain-values/#findComment-935909 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%'; Link to comment https://forums.phpfreaks.com/topic/177502-solved-stopping-a-while-loop-for-certain-values/#findComment-935910 Share on other sites More sharing options...
sc00tz Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks! Solved! Link to comment https://forums.phpfreaks.com/topic/177502-solved-stopping-a-while-loop-for-certain-values/#findComment-935927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.