简体   繁体   English

PHP倒数SQL行从总行减少到0

[英]PHP Countdown SQL Rows from Total Rows to 0

I couldn't quite find what I was look for by googling or searching stackoverflow, so I'm just gonna ask it. 我无法通过谷歌搜索或搜索stackoverflow来找到所需的内容,所以我只想问问它。

$reply_sql = mysqli_query($successconnect, "SELECT * FROM replies WHERE reply_thread = '" . $reply_thread_id . "' ORDER BY reply_date DESC LIMIT $cur, $max");
$numbb = ((20 - (20 * $page)) * -1);
while($reply_row = mysqli_fetch_assoc($reply_sql)) {
$numbb++;

This will result in each reply row counting from 1 up to the total amount of rows. 这将导致每个答复行从1到行总数进行计数。 That is all fine if I want my replies to order ASC. 如果我希望订购ASC的答复就可以了。

I want it to go from total amount of rows down to 0. I imagine this is all math, but I'm really bad at it. 我希望它从总行数减少到0。我想这全是数学,但我真的很烂。 And maybe there's an easier way to do this. 也许有一种更简单的方法可以做到这一点。

$numbb--;

This I know about, but I tried many variations of $numbb and couldn't quite figure out a way to make for instance: 我知道这一点,但是我尝试了$ numbb的许多变体,例如,还不太想办法:

23 (Total Replies) 1 (Page 1) makes it count from 23 down to 3
23 (Total Replies) 2 (Page 2) makes it count from 3 down to 1

It took me a while of trying different combinations, but I had to move around the original code with 23 or replycount in mind to get the result I need. 我花了一段时间尝试各种不同的组合,但是我不得不在原始代码中加上23或Replycount来解决,以获得所需的结果。

$numbb = ((($replycount + 20) - (20 * $page)) + 1);
while($reply_row = mysqli_fetch_assoc($reply_sql)) {
$numbb--;

23 + 20 = 43 - 20 * 1 = 23 + 1 = 24 which $numbb shows as 23 with the first row. 23 + 20 = 43-20 * 1 = 23 + 1 = 24,其中$ numbb在第一行中显示为23。 And then 23 + 20 = 43 - 20 * 2 = 3 + 1 = 4 which shows as 3 on page 2. 然后23 + 20 = 43-20 * 2 = 3 +1 = 4(在第2页上显示为3)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM