我决定在这里重新编写并详细说明,而不是再发布一次。此查询是否可以更改为执行两个功能?
我收到了jtheman的以下代码,它允许我从我的数据库中选择52个更新,并添加一个新的并每周删除一个旧的。它的工作绝对完美。
他的代码:
$starttime = strtotime("28 December 2012"); // a recent Friday
$week = 7 * 24 * 60 * 60; // time value of a week
$posts = 185; // number of posts in your db
$limit = 52; // number of shown posts
$offset = floor((time()-$starttime)/$week); // rounds down difference in weeks from startdate until now
while ($offset>$posts-$limit) $offset = $offset - ($posts-$limit);
// this will start over when you have reached the end of the cycle ie offset 148...
而且我的查询:
// retrieve all update details
$conn = dbConnect('query');
$sql = "SELECT *
FROM updates
WHERE flag_live = 'Y'
ORDER BY update_id DESC
LIMIT ".$offset.",".$limit;
$result = $conn->query($sql) or die(mysqli_error());
$uInfo = $result->fetch_assoc();
再次,这完美的作品。新问题是,我在一个页面上获得了52个更新,我希望能够设置每页4个,并滚动13个页面而不是一个长页面。
所以,我想要做的就是改变这个查询,以便选择52个更新(并且每个星期五添加一个新的更新并删除一个旧的更新),但是在哪里我只能显示4个在页面上的时间。我意识到这不是一个分页问题,因为这是编写查询本质上做两个功能。
这可以通过子查询来完成吗?我可以使用jQuery滑块或等价物来完成分页,但我真的想避免这种情况。
非常感谢!
那么你卡在哪里? – hafichuk
呃...就像如何使它工作。如何获取上面的代码并将52条记录拖到页面上。 – wordman
最好的办法是在客户端做这些操作看看http://www.datatables.net/ – Moes