WebGuyRI Posted August 1, 2009 Share Posted August 1, 2009 Using new code picked up here from a previous problem I was having. This code is really working fine and gives me what I need. The issue is I need to limit the number of rows returned. Thanks in advance $query = "SELECT CONCAT('',name,name2,name3,name4,name5,name6,name7,name8,name9,name10) as n FROM $usertable HAVING n LIKE '%$name%'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['n'] . "<br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/168432-solved-need-to-limit-returns/ Share on other sites More sharing options...
ludjer Posted August 1, 2009 Share Posted August 1, 2009 just add to your while loop a and expression $query = "SELECT CONCAT('',name,name2,name3,name4,name5,name6,name7,name8,name9,name10) as n FROM $usertable HAVING n LIKE '%$name%'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); $i = 0; if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)&& $i != $maxrows) { $i++; print $row['n'] . "<br/>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/168432-solved-need-to-limit-returns/#findComment-888467 Share on other sites More sharing options...
Philip Posted August 1, 2009 Share Posted August 1, 2009 Use the LIMIT syntax. adding a LIMIT 2 to the end of your query will only return 2 rows: SELECT CONCAT('',name,name2,name3,name4,name5,name6,name7,name8,name9,name10) as n FROM $usertable HAVING n LIKE '%$name%' LIMIT 2 Quote Link to comment https://forums.phpfreaks.com/topic/168432-solved-need-to-limit-returns/#findComment-888468 Share on other sites More sharing options...
WebGuyRI Posted August 1, 2009 Author Share Posted August 1, 2009 Great help and thanks for being patient, worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/168432-solved-need-to-limit-returns/#findComment-888472 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.