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
  • 11,605
  • 25
  • 69
  • 96

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
  • 34,669
  • 9
  • 84
  • 115
2
SELECT * FROM comments WHERE approved = 1 LIMIT 3,SOME_HUGE_NUMBER

See this post for more info

Community
  • 1
  • 1
Amarghosh
  • 58,710
  • 11
  • 92
  • 121
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
  • 46,566
  • 21
  • 122
  • 156