I'm trying to limit the number of rows returned from a query. This is the code i'm using.
$min = ($id2-1)*16;
$max = $id2*16;
$row = mysql_query("SELECT * FROM anunt WHERE masina = 2 ORDER BY anuntID DESC LIMIT $min, $max") or die(mysql_error());
ID2 is a value parsed from the link. So when ID2 is 2 for example, the query should have a limit from 16 to 32 - so a total of 16 entries. But my problem is that the query is returning me 32 entries. It's like it's jumping over the '$min' value. I quad checked everything and in the end, that query seems the problem.
Any ideas? Thanks
Replace this:
$row = mysql_query("SELECT * FROM anunt WHERE masina = 2 ORDER BY anuntID DESC LIMIT $min, $max") or die(mysql_error());
by this:
$records = $max - $min;
$row = mysql_query("SELECT * FROM anunt WHERE masina = 2 ORDER BY anuntID DESC LIMIT $records, $min") or die(mysql_error());
语法为LIMIT start_index, amount
,而不是LIMIT start_index, end_index
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
You pass row_count=32.
Check manual .
use LIMIT
your query LIMIT FROM TO
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.