0

拜托,我在这里有这段代码,我用它来检索我拥有的数据库的一些信息。

现在,我也有一个搜索框,我的问题是它没有搜索,我的意思是搜索不起作用。

请看一下..

<script type="text/javascript">
        var url;
        function doSearch(){
        $('#dg').datagrid('load',{
            user_id: $('#user_id').val()
        });
        $('#dg').datagrid('reload');
    }

    </script>
</head>
<body>


    <table id="dg" title="Coupons Requested" class="easyui-datagrid" style="width:1200px;height:350px"
            url="get_coupon.php"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr> 
            <th data-options="field:'ck',checkbox:true"></th>
                <th field="id" width="50">ID</th>
                <th field="user_id" width="50">User ID</th>
                <th field="points" width="50">Points</th>
                                                                                                                                <th field="time" width="50" sortable="true" >Time Added</th>

            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit Record</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">Remove Record</a>

                <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New Record</a>

                 <span>User ID:</span>  
    <input id="user_id" style="line-height:26px;border:1px solid #ccc">
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a> 
    </div>

    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">

        <div class="ftitle">Coupons Information</div>
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>ID</label>
                <input name="id" class="easyui-validatebox" readonly>
            </div>

                     <div class="fitem">
                    <label>User ID:</label>
                <input name="user_id">
            </div>

                     <div class="fitem">
                    <label>Points:</label>
                <input name="points">
            </div>



             <div class="fitem">
                    <label>Time added:</label>
                <input name="time">
            </div>

        </form>
    </div>

    <script>
    $('#dg').datagrid({singleSelect:false});
    </script>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">Save</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>
    </div>
</body>

和 php

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'time';  
$order = isset($_POST['order']) ? strval($_POST['order']) : 'desc'; 
$user_id = isset($_POST['user_id']) ? mysql_real_escape_string($_POST['user_id']) : '';   
    $offset = ($page-1)*$rows;
    $result = array();  

include 'conn.php';  

$rs = mysql_query("select count(*) from coupon where user_id like '%$user_id%'");  
$row = mysql_fetch_row($rs);  
$result["total"] = $row[0];  

$rs = mysql_query("select * from coupon where user_id like '%$user_id%' order by $sort $order limit $offset,$rows");  

$items = array();  
while($row = mysql_fetch_object($rs)){  
    array_push($items, $row);  
}  
$result["rows"] = $items;  

echo json_encode($result);
4

0 回答 0