在mysql中选择一系列值

时间:2010-07-07 05:34:00

标签: php mysql

如何在MySql查询中选择除前三行之外的所有行?

$query = mysql_query("SELECT * FROM comments WHERE approved = 1");  

3 个答案:

答案 0 :(得分:2)

您想要以下内容:

$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
    }
}

答案 1 :(得分:2)

SELECT * FROM comments WHERE approved = 1 LIMIT 3,SOME_HUGE_NUMBER

See this post for more info

答案 2 :(得分:0)

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

要按columnName使用

查找第三个记录顺序
$query = mysql_query("SELECT * FROM comments
                                     WHERE approved = 1 
                                     ORDER BY columnName 
                                     LIMIT 2, 1");

要查找除前3行以外的所有内容,请使用LIMIT 2, total_no_of_rows

如果你不知道total_no_of_rows使用非常大的数字而不是它。

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