开发者

select a range of values in mysql

How would I select all but the first 3 rows in my MySql 开发者_运维技巧query?

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


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

See this post for more info


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


$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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜