tags:

views:

32

answers:

4

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

+3  A: 
SELECT * FROM myTable LIMIT 4;
SELECT * FROM myTable LIMIT 4,4;
Delan Azabani
+1  A: 
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.

The MYYN
A: 

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
A: 

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