關於order by問題

來源:互聯網
上載者:User
類似這種的

比如說www.xxx.com/index.php?id=5&order=zhucetime

$order=$_GET['order'];
$id=$_GET['id'];


$sqltext="select * from table where n_pid='".$id."' order by '".$order."' asc";





如何?第一次點擊的時候是按asc排序 第二次點擊後是按照desc排序 不斷的迴圈切換啊?

如何?第一次點擊的時候是按asc排序 第二次點擊後是按照desc排序 不斷的迴圈切換啊?


回複討論(解決方案)

你需要傳遞當前排序的方式

給個預設只,頁面傳遞兩個陣列變數你排序的欄位,和方式呀

我的意思是 第一次點記的時候是按照 asc排序 第二次點擊的時候 怎麼變成desc排序呢 給你代碼..新手

我寫一個只有一個條件的:

$by1=$_GET['by1'];//頁面的排序條件如desc,asc$order=$_GET['order'];$id=$_GET['id'];if(!$by1){$sqltext="select * from table where n_pid='".$id."'  order by '".$order."'  asc";}else{$sqltext="select * from table where n_pid='".$id."'  order by '".$order."'  $by1";}

if(!isset($_SESSION['direction']) || $_SESSION['direction'] == 'desc'){   $_SESSION['direction'] = 'asc';}else{   $_SESSION['direction'] = 'desc';}$sql = "select * from table where n_pid='".$id."'  order by  ".$order."  ".$_SESSION['direction'];

需要多傳遞一個升降序參數。每次點的時候用js更改這個參數值。

另外,你這樣不對輸入做任何校正過濾直接放sql裡非常危險!

呵呵 5樓的方法正確....有簡單點的嗎? jquery 之類的..或者其他方法

結貼...閃人 呵呵....

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.