目前我正在使用
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());
答案 0 :(得分: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);