napap Posted June 9, 2011 Share Posted June 9, 2011 How can i limit amount of mysql results? Hi, i need som help with php and mysql. I am creating a search function for my websites, i am using a variable to hold the results of a mysql query, like this: $query = "SELECT * FROM database". then i am using a while statement to "echo" out the results... however, i would like to show only 10 results per page, and then have a next button or link to show the next 10 results... how can this be done? thanks... Quote Link to comment https://forums.phpfreaks.com/topic/238923-how-can-i-limit-amount-of-mysql-results/ Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2011 Share Posted June 9, 2011 What you're looking for is called pagination, and there's a tutorial on the main part of the site, here: http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/238923-how-can-i-limit-amount-of-mysql-results/#findComment-1227716 Share on other sites More sharing options...
revraz Posted June 10, 2011 Share Posted June 10, 2011 But to answer your actual question, you would use LIMIT in your SQL call. Quote Link to comment https://forums.phpfreaks.com/topic/238923-how-can-i-limit-amount-of-mysql-results/#findComment-1227769 Share on other sites More sharing options...
Pikachu2000 Posted June 10, 2011 Share Posted June 10, 2011 If you think that was the answer to the question, you must not have read past the first sentence. Quote Link to comment https://forums.phpfreaks.com/topic/238923-how-can-i-limit-amount-of-mysql-results/#findComment-1227789 Share on other sites More sharing options...
xyph Posted June 10, 2011 Share Posted June 10, 2011 If you're performing a search using LIKE, rather than just a usual select query with a static or no where clause, it might be worth it to just grab all results and flip through them with javascript. Save performing a bunch of cpu-heavy queries. Quote Link to comment https://forums.phpfreaks.com/topic/238923-how-can-i-limit-amount-of-mysql-results/#findComment-1227791 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.