我不知道如何从数据库中检索最新的第3条记录。对此提出相关的疑问。
$sql = " select top 3 from chat ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['message'];
}
} else {
echo "0 results";
}这是我的数据库
user_id message sent_on
2 Ask relevent question 2017-06-20 20:04:56
2 i don,t know 2017-06-20 20:04:48
1 having cup of tea 2017-06-20 20:04:46
2 thank you 2017-06-20 20:04:39发布于 2017-06-21 07:07:34
要从数据库中获取第n条记录,请使用以下mysql查询
SELECT * FROM table ORDER BY ID LIMIT n-1,1从表中获取前三条记录,这是最近插入的
SELECT * FROM table ORDER BY sent_on LIMIT 0,3https://stackoverflow.com/questions/44669005
复制相似问题