我尝试制作一个以Feed格式显示图像的应用程序...数据库中的图像一次从顶部(第一行)加载3个,但我希望它从下到上显示数据库中的项目因为新插入的项目会转到列表的底部...如何以相反的顺序加载表格?因此它显示从数据库表底部到表顶部的行。
这是我的代码...所有文件名为" Chat.php"
<?php
//Getting the page number which is to be displayed
$page = $_GET['page'];
//Initially we show the data from 1st row that means the 0th row
$start = 0;
//Limit is 3 that means we will show 3 items at once
$limit = 3;
//Importing the database connection
require_once('dbConnect.php');
//Counting the total item available in the database
$total = mysqli_num_rows(mysqli_query($con, "SELECT id from feed "));
//We can go atmost to page number total/limit
$page_limit = $total/$limit;
//If the page number is more than the limit we cannot show anything
if($page<=$page_limit){
//Calculating start for every given page number
$start = ($page - 1) * $limit;
//SQL query to fetch data of a range
$sql = "SELECT * from feed limit $start, $limit";
//Getting result
$result = mysqli_query($con,$sql);
//Adding results to an array
$res = array();
while($row = mysqli_fetch_array($result)){
array_push($res, array(
"name"=>$row['name'],
"publisher"=>$row['publisher'],
"image"=>$row['image'])
);
}
//Displaying the array in json format
echo json_encode($res);
}else{
echo "over";
}
答案 0 :(得分:0)
//SQL query to fetch data of a range
$sql = "SELECT * from feed limit $start, $limit";
更新这些行,如
//SQL query to fetch data of a range
$sql = "SELECT * from feed ORDER BY 'feed .id' DESC limit $start, $limit";