1

How would I select all but the first 3 rows in my MySql query?

$query = mysql_query("SELECT * FROM comments WHERE approved = 1");  
ian
  • 10,075
  • 23
  • 66
  • 95

3 Answers3

2

Do you want the following:

$query = mysql_query("SELECT * FROM comments WHERE approved = 1");
$rowCount = 0;
while ($row = mysql_fetch_assoc($query)) {
    $rowCount = $rowCount + 1;
    // do stuff only if you have reached the third row.
    if ($rowCount > 3){
        // do stuff here
    }
}
phimuemue
  • 30,699
  • 8
  • 74
  • 109
2
SELECT * FROM comments WHERE approved = 1 LIMIT 3,SOME_HUGE_NUMBER

See this post for more info

Community
  • 1
  • 1
Amarghosh
  • 55,378
  • 11
  • 87
  • 119
0
$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 3");

To find third record order by columnName use

$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 2, 1");

To find All other than 1st 3 rows use LIMIT 2, total_no_of_rows

if you don't know total_no_of_rows use very large number instead of it.

$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 2, total_no_of_rows");
Salil
  • 43,381
  • 19
  • 113
  • 148