如何在MySql查询中选择除前三行之外的所有行?
$query = mysql_query("SELECT * FROM comments WHERE approved = 1");
答案 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
答案 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");