-1

目前我正在使用

select text, tid from notifications where user = '".$_SESSION['id']."' ORDER BY id asc

但如果我使用:

select text, tid from notifications where user = '".$_SESSION['id']."' ORDER BY id asc LIMIT 0,25 

它只查看前 25 个。它必须是最新的 25 个。我该怎么做?

认为我解决了这个问题?

$total = mysql_query("select id from notifications where user = '".$_SESSION['id']."'");
$total = mysql_num_rows($total)-25;

$l = mysql_query("select text, tid from notifications where user = '".$_SESSION['id']."' ORDER BY id asc limit $total,25") or die ( mysql_error());
4

1 回答 1

2

ORDER BY id desc代替ORDER BY id asc

mysql_query("select text, tid from notifications where user = '".$_SESSION['id']."' ORDER BY id DESC LIMIT 0,25") or die ( mysql_error() );

应该不需要您在最新编辑中提到的额外查询。正如我所提到的,只需调整显示数据的循环,使其首先显示最后一项,然后再下线。

例如(仅以标准数组为例,因为我不知道您的数据库返回什么):

$items = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25); // Here you would use mysql_fetch_array or equivalent to get your array of items

$count = count($items); // Here you would use mysql_num_rows($items);

// Then, run through each item, starting with 25 (the last) and going backwards until 0.
do {
    echo $items[$count] . "<br/>";
    $count--;
}
while($count >= 0);
于 2012-11-29T21:09:22.340 回答