且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 反转 MySQL DB 的结果顺序

更新时间:2023-11-30 11:41:28

您有两个解决方案:

  1. 对链接进行降序排序
  2. 使用 array_reverse 或 rsort

解决方案#1:

"SELECT * FROM notfi1 WHERE Own='" .$_GET['u']. "' ORDER BY UserId DESC"

解决方案#2:

$result = mysql_query("SELECT * FROM notfi1 WHERE Own='" .$_GET['u']. "'");
while($row = mysql_fetch_array($result))
{
    $data[] = $row['UserId'];
}
rsort($data);
foreach($data as $item){
    echo 'link:<a href=member.php?u=' .$row['UserId']. '>text</a><br>';
}

第二种方法更好,因为这意味着您将数据检索与显示分开...应该这样做,但不会阻止您在 MySQL 服务器上对数据进行排序

Second method is better because it means you are seperating your data retrieval from your display... IT SHOULD be done this way but doesn't prevent you to sort your data on the MySQL Server