$query = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC LIMIT 1";$result = $conn->query($query);
此查询仅提取最后一个,我可以在第1节中查看
$query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";$result2 = $conn->query($query2);
此查询提取要在第2部分中查看的所有数据
我在query2中需要进行哪些更改,以便它可以提取除最后一个数据之外的所有数据?
答案 0 :(得分:0)
如果,id
列是primary key
和auto-incremented
。
$query2 = "SELECT id,subject,date,notice
FROM sam_notice
WHERE id < (SELECT MAX(id) FROM sam_notice)";
答案 1 :(得分:0)
尝试
SELECT id,subject,date,notice
FROM sam_notice
WHERE id != (SELECT MAX(id) FROM sam_notice
答案 2 :(得分:0)
不要寻找SQL方式。相反,在使用结果时,只需跳过第一行(这是您使用DESC
后的最后一行)。像这样:
$query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";
$result2 = $conn->query($query2);
$begin = TRUE;
while ($row = <some fetch method on $result2, depending on your current API>) {
if($begin) {
$begin = false;
continue;
}
// use other rows...
}