-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() );

最新の編集で言及した追加のクエリは必要ありません。前述したように、データを表示するループを調整して、最後のアイテムを最初に表示してから下に移動するようにします。

たとえば(DBが何を返すかわからないため、例として標準配列を使用しています):

$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 に答える