我没有得到如何从database.suggest中检索最新的没有第3条记录的相关查询。
here is my code
$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";
}
here is my database
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
答案 0 :(得分:1)
要从数据库获取第n条记录,请使用此mysql查询
SELECT * FROM table ORDER BY ID LIMIT n-1,1
获取最近插入的表格中的前三个记录
SELECT * FROM table ORDER BY sent_on LIMIT 0,3