ldb358 Posted June 11, 2009 Share Posted June 11, 2009 i want it to list the first 10 results thanks in advanced heres my code: function runBrowse($search){ $qSearch = mysql_query("SELECT * FROM users WHERE username LIKE '%$search%'"); $results = mysql_fetch_array($qSearch); if($results['username'] != ""){ echo $results['username']; }else{ echo "no results"; } } Link to comment https://forums.phpfreaks.com/topic/161875-listing-multiple-results-from-a-mysql-query/ Share on other sites More sharing options...
ted_chou12 Posted June 11, 2009 Share Posted June 11, 2009 function runBrowse($search){ $qSearch = mysql_query("SELECT * FROM users WHERE username LIKE '%$search%'" LIMIT 10); while($results = mysql_fetch_array($qSearch)) { if($results['username'] != ""){ echo $results['username']; }else{ echo "no results"; } }} Link to comment https://forums.phpfreaks.com/topic/161875-listing-multiple-results-from-a-mysql-query/#findComment-854063 Share on other sites More sharing options...
Maq Posted June 11, 2009 Share Posted June 11, 2009 There's no reason to check if the username is blank when you have the LIKE clause that only selects the usernames with search in them. If they are blank, they won't be selected. Try: function runBrowse($search){ $qSearch = mysql_query("SELECT * FROM users WHERE username LIKE '%$search%' LIMIT 10"); while($results = mysql_fetch_array($qSearch)) { echo $results['username']; } } And please learn to properly, or at least consistently, indent and format. Link to comment https://forums.phpfreaks.com/topic/161875-listing-multiple-results-from-a-mysql-query/#findComment-854065 Share on other sites More sharing options...
ldb358 Posted June 11, 2009 Author Share Posted June 11, 2009 thanks for the help Link to comment https://forums.phpfreaks.com/topic/161875-listing-multiple-results-from-a-mysql-query/#findComment-854070 Share on other sites More sharing options...
ted_chou12 Posted June 11, 2009 Share Posted June 11, 2009 btw, if you want to tell ur users that there are no results, change to this: function runBrowse($search){ $qSearch = mysql_query("SELECT * FROM users WHERE username LIKE '%$search%' LIMIT 10"); $rows = mysql_num_rows($qSearch); if ($rows == 0) { echo "no results";} else { while($results = mysql_fetch_array($qSearch)) {echo "no results";} }} Ted Link to comment https://forums.phpfreaks.com/topic/161875-listing-multiple-results-from-a-mysql-query/#findComment-854075 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.