问题描述
我的网站当前基于rowid提取我的内容,但是根据DESC顺序为其提供页码。这对某些人来说是可以的,但是当我在网站上添加新文章并且有人单击下一步按钮时,如果我在他们单击下一步按钮的时间内添加新页面,有时可以将他们带到同一页面。
My website currently pulls my content based on rowid, however it gives it a page number based on DESC order. This is ok to some, however when I add a new article to my website and someone clicks the next button it can sometimes take them to the same page if I add new page within the time they clicked the next button.
$limit = 1;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * $limit;
$sql = "SELECT * FROM article ORDER BY id DESC LIMIT $start_from, $limit";
$rs_result = mysql_query ($sql);
我仍然希望显示数据库中的最后一个条目(最高行ID)。好奇我在做什么错。
I still want the last entry in my database (highest row id) to be displayed. Curious what I am doing wrong.
推荐答案
弄清楚了。这样一来,当用户访问您的index.php页面时,会将他们重定向到最新帖子。我为pageid添加了一个表格,并将其设置为9999999999。我怀疑是否可以发布这么多内容。
Figured it out. This makes it so when the user visits your index.php page it redirects them to the newest post. I added a table for pageid and set it at 9999999999. I doubt I could post that much content.
<?php
$rowcountprep = mysql_query("SELECT * FROM articles");
$rowcount = mysql_num_rows($rowcountprep);
if (!$_GET["page"])
{
$total = '10000000000';
$current = $total-$rowcount;
?>
<script>window.location="example.com/index.php?page=<?php echo
$current; ?>"</script>
<?php
}
?>
感谢@SloanThrasher的帮助。
Thanks to @SloanThrasher for the help.
这篇关于如何根据ID获取页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!