开发者

how to split mysql row [duplicate]

This question already has answers here: 开发者_如何学Go Closed 10 years ago.

Possible Duplicate:

How do you implement pagination in PHP?

how to split mysql row? i have 12 row in my table then i want to display first 4 row and next display 4 row how to use please tell


SELECT * FROM myTable LIMIT 4;
SELECT * FROM myTable LIMIT 4,4;


SELECT * FROM `your_table` LIMIT 0, 4 

This will display the first 4 results from the database.

SELECT * FROM `your_table` LIMIT 7, 11

This will show records 8, 9, 10, 11.


Use the SQL LIMIT clause:

SELECT ... LIMIT offset, max-result-set-size;

So, for the first 'page' you'd want LIMIT 0, 4, and then subsequently increment the offset by 4, eg:

LIMIT 0, 4
LIMIT 4, 4
LIMIT 8, 4

More information is available in the mySQL documentation...


Presuming you want to display all of these sections at once, only with a visual divider:

$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numberRows = 1;

while ($row) {

  if (($numberRows % 4) == 0) {
    echo "<hr>";
  }

  // display whatever $row data you need to
  var_dump($row);

  $row = mysql_fetch_array($result, MYSQL_ASSOC);
  $numberRows++;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜