我一直在尝试选择数据库中项目表中的最新行,并显示标题,描述以及存储在单独文件夹中的项目图像,但路径存储在同一个表中。我可以显示行,但我的上一个按钮不起作用,它会转到第一行。我希望每次单击它时都会向后移动一行。请帮忙。以下是我的代码
<?php
include("scripts/connection.php");
session_start();
if (empty($_SESSION["username"])){
header("Location:login.php");
}
$posts = "SELECT ID, Title, Description, PostDate, Image1, Image2, Image3 FROM items Order By PostDate";
$select = mysql_query($posts);
$numrows = mysql_num_rows($select);
if (isset($_POST['previous'])){
For($i=1,$i>=0,$i--){
mysql_data_seek ($select, $i);
$row=mysql_fetch_assoc($select);
$ID ="$row[ID]";
$title = "$row[Title]";
$datetime = "$row[PostDate]";
$image1 = "$row[Image1]";
$image2 = "$row[Image2]";
$image3 = "$row[Image3]";
$description = "$row[Description]";
}
}else{
while ($row = mysql_fetch_assoc($select)){
$ID ="$row[ID]";
$title = "$row[Title]";
$datetime = "$row[PostDate]";
$image1 = "$row[Image1]";
$image2 = "$row[Image2]";
$image3 = "$row[Image3]";
$description = "$row[Description]";
}
}
?>
答案 0 :(得分:0)
尝试按日期降序排序:
$posts = "SELECT ID, Title, Description, PostDate, Image1, Image2, Image3 FROM items Order By PostDate desc ";