php - 反转数据
问题描述
我希望你一切都好。嗯,我正在聊天室工作,我面临的问题是,当页面加载时它显示第一条消息,我正在考虑如何让它在页面加载时显示最后一条/新消息...... .这是我显示数据的代码:
</div>
<!-- Sidebar -->
<div class="w3-sidebar w3-light-grey w3-bar-block" style="width:83.6%;height:75.4%">
<h3 class="w3-bar-item">Menu</h3>
<div id="display"></div>
</div>
<div class="w3-sidebar w3-light-grey w3-bar-block" style="width:16.5%;height:75.4%;margin-left:1140px;">
<h3 class="w3-bar-item">Menu</h3>
<div>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
<h1>asdasd</h1>
</div>
</div>
<script>
setInterval(function(){
$('#display').load("pages/get.php").fadeIn("slow");
}, 1000);
</script>
获取.php:
<?php
require('../system/db.php');
global $con;
$get = mysqli_query($con,"SELECT * FROM zadx_chat ORDER BY id");
if(mysqli_num_rows($get) > 0){
while($row = mysqli_fetch_array($get)){
echo "<p>" . $row['message'] . "</p>";
}
}
?>
解决方案
检查您的 page.php,如果有查询以获取消息,请确保将该查询更改为降序。就像如果有 ORDER BY table_column ASC 然后将其更改为 ORDER by table_column DESC。那应该对你有用。