0

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

Community
  • 1
  • 1

4 Answers4

3
SELECT * FROM myTable LIMIT 4;
SELECT * FROM myTable LIMIT 4,4;
Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
1
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.

miku
  • 181,842
  • 47
  • 306
  • 310
0

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...

jstephenson
  • 2,170
  • 14
  • 14
0

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++;
}
erisco
  • 14,154
  • 2
  • 40
  • 45