2012-04-14 56 views
0

我有一個以表格格式顯示的默認列表。現在在桌子上方,我有一個排序選項。現在,沒有給出該排序選項的表單和按鈕,我應該如何根據選擇的順序從下拉選擇框中選擇更改記錄。 我想通過使用jQuery來做到這一點。但最終,在vain.My代碼去像:根據訂單的選擇重新排列列表

<?php 
$other_account_sql = "SELECT `admin_id`,`username`,`admin_name`,`role`,`status`,`email`,`contact_no`,`location`,`creation_date` FROM `admin_details` WHERE `username` <> '".$_SESSION['existingUser']."'"; //this is for getting default lists 
?> 

<!-- html code--> 
<select name="sort_selection" id="sort_selection" class="soring_select"> 
    <option value="">--Select One--</option> 
    <option value="admin_name" >Name</option> 
    <option value="email" >Email Id</option> 
    <option value="location">Location</option> 
    <option value="contact_no">Contact No</option> 
</select> 
<!--end of html code--> 

<!-- js code--> 
<script type="application/javascript" src="js/jquery-1.7.2.js" language="javascript"></script> 
<script type="application/javascript"> 
    $(document).ready(function(){ 
    $('#sort_selection').change(function(){ 
    var str = ""; 
    $("select option:selected").each(function() { 
     str += $(this).text() + " "; 
    }); 
    }); 
    }); 
</script> 
<!-- end of js code--> 

現在我的問題是,我應如何根據選擇更改查詢? 請幫幫我。

回答

1

在這裏你去朋友

<?php 
$other_account_sql = "SELECT `admin_id`,`username`,`admin_name`,`role`,`status`,`email`,`contact_no`,`location`,`creation_date` FROM `admin_details` WHERE `username` <> '".$_SESSION['existingUser']."'" ORDER BY ". $_POST['sort_selection'].: ASC; 
?> 

好運

+0

但我不應該點擊提交按鈕......然後怎麼$ _ POST [「sort_selection」]將會得到些什麼? – John 2012-04-14 13:37:33

+0

謝謝,我解決了這個問題。 – John 2012-04-14 13:54:46