从数据库mysql获取N值

i have a table i get cars form databases and i list it in this table:

$row_id=$_GET["id"];
$solK = ($row_id-1) * 9;
$sagK = ($row_id) * 9;
$sorgu2 = mysql_query("SELECT * FROM Car WHERE Car_ID > '$solK' AND Car_ID < '$sagK'");

Every page have 9 cars i use id for sort these cars but when i delete a car (for example Carid=5) in first page have 8 cars but other pages have 9 cars how can i get first N values without CarId from databases can you explain with sql codes.

Add a LIMIT to your query.

For example

SELECT * FROM tbl LIMIT 0, 9

will select the first 9 entries from tbl.

In order to match your query and preserve the ordering I'd state it as

SELECT * FROM Car ORDER BY Car_ID LIMIT 0, 9

for the first nine rows. For the next nine rows, just increment both numbers by 10 and so on.

Rather than code it like you have done, just use LIMIT:

SELECT * FROM Car LIMIT 0,9

then

SELECT * FROM Car LIMIT 9,9

I assume the other answers (using limit and offset) will be suited for your case. But if you (or anyone else) ever need to improve performance, and need to manage fast queries for more than the first few pages, you should implement paging like this:

  SELECT f1, f2, ... 
    FROM tbl
      WHERE Car_ID > $id
    ORDER BY Car_ID
    LIMIT 10

Use "LIMIT offset, row_count" in you statement

Try this SQL statement SELECT * FROM Car LIMIT '$pageN*$nperpage', '$nperpage'

Where $nperpage will be a number of items per page and $pageN will be a page number (note that in this case page numbering starts with 0).

http://dev.mysql.com/doc/refman/5.0/en/select.html