根据订单的选择重新排列列表

时间:2012-04-14 12:20:15

标签: php jquery mysql

我有一个以表格格式显示的默认列表。现在在表格上方,我有一个排序选项。现在没有给出该排序选项的表单和按钮,如何根据下拉选择框中的选项顺序更改记录。   我试图通过使用jquery来做到这一点。但最终,徒劳无功。我的代码就像:

<?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 个答案:

答案 0 :(得分: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;
?>
祝你好运