Canman2005 Posted November 11, 2008 Share Posted November 11, 2008 Hi all I have a query to grab all rows in my table but it has a LIMIT 20 on it, so it just grabs the first 20 rows. I want to do a SELECT COUNT(*) as Num FROM but only do a count within the LIMIT I have set for my query. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/132267-count-within-limit/ Share on other sites More sharing options...
BioBob Posted November 11, 2008 Share Posted November 11, 2008 LIMIT should accept two arguments. If its given just one it takes it as the high end. Like ...LIMIT 20; and LIMIT 0,20; are the same. You can change the 0 to make that your starting point, so for 20 rows starting at 10 it would be LIMIT 10, 30; Is that what you were asking or did I misunderstand you? Quote Link to comment https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687625 Share on other sites More sharing options...
sasa Posted November 11, 2008 Share Posted November 11, 2008 1st grab data and then count grabed rows @BioBob Format of LIMIT in MySQL is 'LIMIT start, lenght', not 'LIMIT start, end' Quote Link to comment https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687736 Share on other sites More sharing options...
Adam Posted November 11, 2008 Share Posted November 11, 2008 $limit = 'LIMIT 0, 20'; mysql_query("SELECT * FROM ... {$limit}"); // blah blah // do some stuff! mysql_query("SELECT COUNT(*) as Num FROM ... {$limit}"); If you were wanting to pass the start value in the URL like say: "?start=20" you could use: $start = (!$_GET['start']) ? 0 : (int) $_GET['start']; $limit = 'LIMIT {$start}, {$start+20}'; (no code tested) Adam Quote Link to comment https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687752 Share on other sites More sharing options...
Canman2005 Posted November 11, 2008 Author Share Posted November 11, 2008 thanks guys, much help Quote Link to comment https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687798 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.