Jump to content

COUNT within LIMIT


Canman2005

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687625
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/132267-count-within-limit/#findComment-687752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.