I have created a gallery using a database. All the images are showing randomly on Home page. Now I need to add a new "Latest"index.php/latest.php
category to my navigation bar.
我使用数据库创建了一个库。所有图像都在主页上随机显示。现在我需要在我的导航栏中添加一个新的“Latest”index.php / latest.php类别。
I'm using infinite scroll and a little trick to order randomly$rand=date("i");
.
我正在使用无限滚动和一个小技巧随机订购$ rand = date(“i”);.
Question: ORDER BY 1 DESC
is not working on index.php/latest.php
, because I have ordered by randomly on the Home page. How could I order by descending order on the Latest page without changing the Home page order?
问题:ORDER BY 1 DESC无法处理index.php / latest.php,因为我已在主页上随机排序。如何在不更改主页订单的情况下按最新页面的降序排序?
index.php
<?php
include ("sqli.php");
$rand=date("i");
$seed=($rand);
$per_page = 9;
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else {
$page=1;
}
$start_from = ($page-1) * $per_page;
$query = "SELECT * FROM data ORDER BY RAND($rand) LIMIT $start_from, $per_page";
$result = mysqli_query ($con, $query);
<?php while ($row = mysqli_fetch_array($result)) { ?>
?>
<div id="gallery here"></div>
<?php> } ?>
latest.php
<?php
include ("sqli.php");
$per_page = 9;
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else {
$page=1;
}
$start_from = ($page-1) * $per_page;
$query = "SELECT * FROM data ORDER BY 1 DESC LIMIT $start_from, $per_page";
$result = mysqli_query ($con, $query);
?>
<?php while ($row = mysqli_fetch_array($result)) { ?>
?>
<div id="gallery here"></div>
<?php> } ?>
2 个解决方案
#1
You have to set order by createdAt field(by your date field) in last.php:
您必须在last.php中按createdAt字段(按日期字段)设置顺序:
$query = "SELECT * FROM data ORDER BY createdAt DESC LIMIT $start_from, $per_page";
#2
This issue was solved by me. This issue related to infinite-scroll navigation. I hope my PHP code will help to someone. You can use this PHP code for jQuery Infinite-Scroll pagination. I'm here if you have any question. Thanks all.
这个问题由我解决了。此问题与无限滚动导航有关。我希望我的PHP代码可以帮助某人。您可以将此PHP代码用于jQuery Infinite-Scroll分页。如果你有任何问题我就在这里。谢谢大家。
#1
You have to set order by createdAt field(by your date field) in last.php:
您必须在last.php中按createdAt字段(按日期字段)设置顺序:
$query = "SELECT * FROM data ORDER BY createdAt DESC LIMIT $start_from, $per_page";
#2
This issue was solved by me. This issue related to infinite-scroll navigation. I hope my PHP code will help to someone. You can use this PHP code for jQuery Infinite-Scroll pagination. I'm here if you have any question. Thanks all.
这个问题由我解决了。此问题与无限滚动导航有关。我希望我的PHP代码可以帮助某人。您可以将此PHP代码用于jQuery Infinite-Scroll分页。如果你有任何问题我就在这里。谢谢大家。