无法根据在搜索字段中输入的值显示表中的数据[关闭]

Posted

技术标签:

【中文标题】无法根据在搜索字段中输入的值显示表中的数据[关闭]【英文标题】:Unable to show the data in table according to the value entered in serach field [closed] 【发布时间】:2020-06-09 13:03:05 【问题描述】:
 <input type="text" id="myInput" class="form-control" onkeyup="myFunction()" placeholder="Seach For Data..." title="Type in a name">  
 <table id="myTable" class="table table-bordered table-striped table-condensed cf">
    <thead class="cf">
    <tr id="headingTR" style="display:yes">
    <th style="text-align:center">Application No.</th>
    <th style="display:none;">ID</th>
    <th style="width:15%;text-align:center" class="numeric">Name</th>
    <th style="width:5%;text-align:center" class="numeric">Moblile No.</th>
    <th style="width:45%;text-align:center" class="numeric">Detail</th>
    <th style="width:10%;text-align:center" class="numeric">Tag</th>
    <th style="width:5%;text-align:center" class="numeric">Status</th>
    <th style="width:10%;text-align:center" >Download</th>
    <th style="width:15%;text-align:center" class="numeric">Action</th>
    </tr>
    <tr id="noRecordTR" style="display:none"> 
    <td>No Data</td>                              
    </tr>
    </thead>
    <tbody id="data">
    <?php 
                include("pagination/function1.php");
    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    $limit = 5; //if you want to dispaly 10 records per page then you have to change here
    $startpoint = ($page * $limit) - $limit;
    $sql_block = "SELECT * FROM citizen_request ORDER BY sno DESC LIMIT $startpoint, $limit";
    $block_data = mysqli_query($con,$sql_block);
    while($row = mysqli_fetch_assoc($block_data) )
                    $id = $row['sno'];
                    $name = $row['name'];
                    $mobile = $row['mobile'];
                    $description = $row['description'];
                    $remark = $row['remark'];
                    $uniqueid = $row['id'];
                    $status = $row['status'];
                    $file = $row['file'];
                    if ($file=="")
                    
                        $file="blank.php";
                    
                    ?> 
    <tr>
    <td data-title="Application No"><?=$uniqueid?></td>
    <td data-title="ID" style="display:none;"><?=$id?></td>
    <td class="numeric" data-title="Name"><?=$name?></td>
    <td class="numeric" data-title="Mobile"><?=$mobile?></td>
    <td class="numeric" data-title="Detail"><?=$description?></td>
    <td class="numeric" data-title="Tag"><?=$remark?></td>
    <td class="numeric"  data-title="Status"> <span class="badge badge-primary"><?=$status?> </span></td>
    <td class="numeric"  data-title="Download"><a class=" btn btn-success btn-sm" href="upload/request/<?=$file?>" target=_blank> Download</a></td>
    <td class="numeric"  data-title="Action">
    <a href="edit-request.php?sno=<?=$id?>" onclick="return confirmation()" ><button class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i></button></a>
    <a href="delete_request.php?sno=<?=$id?>" onclick="return confirmation()"> <button class="btn btn-danger btn-sm"><i class="fa fa-trash-o "></i></button></a>
    </td>
    </tr>
    <?php 
     $sno=$sno+1;
    
    ?>
    </tbody>
    </table>

这是我的表格搜索字段。 这是我的脚本,用于获取用户搜索的数据。

$(document).ready(function()
      $("#myInput").on("keyup", function() 
       var flag = false;
       var value = $(this).val().toLowerCase();
     $.ajax(
                    url: 'getRequestSearch.php',
                    type: 'post',
                    data: value:value,
                    dataType: 'json',

                    success:function(response)

                        var len = response.length;
                        if(len == 0)

                         else
                          var data = "";
                          var sno = 1;
                            for( var i = 0; i<len; i++)
                                var id = response[i]['id'];
                                var name = response[i]['name'];
                                var mobile = response[i]['mobile']; 
                                var description = response[i]['description']; 

                                var remark = response[i]['remark'];
                                var app_no = response[i]['app_no'];
                                var status = response[i]['status'];
                                var file = response[i]['file'];
                                if(file==""||file=="no")
                                
                                    file="blank";
                                else
                                

                                

                                    if(id=="")
                                    

                                    
                                    else
                                    
                                        data += '<tr><td data-title="Application No.">' + app_no + '</td><td data-title="ID" style="display:none;">' + id + '</td> <td class="numeric" data-title="Name">' + name + '</td><td class="numeric" data-title="Mobile">'+ mobile + '</td><td class="numeric" data-title="Description">'+ description +'</td><td class="numeric" data-title="Remark">' +remark+ '</td><td class="numeric"  data-title="Status"><span class="badge badge-primary">'+ status +'</span></td> <td class="numeric"  data-title="Download"><a class=" btn btn-success btn-sm" href="upload/request/'+file+'" target=_blank>Download</a></td><td class="numeric"  data-title="Operation"><a href="edit-request.php?sno='+id+'" onclick="return confirmation()" ><button class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i></button></a><a href="delete_request.php?sno='+id+'" onclick="return confirmation()"> <button class="btn btn-danger btn-sm"><i class="fa fa-trash-o "></i></button></a></td></tr>';  
                                    
                                    sno++;
                    $("#download-excel").attr("href", "excel-request.php?status="+status_sel+"");
                                    $("#download-excel").attr("target","_blank");
                                    $("#download-zip").attr("href", "download-zip-request.php?status="+status_sel+"");
                                    $("#download-zip").attr("target","_blank");


                            
                            $("#data").html(data)
                        



                    


                );
            );
      );

当我输入名称时,它会根据我在搜索字段中输入的内容获取数据作为响应。但表数据没有改变。 还有 m 使用 WHERE name LIKE %$value%;但是我如何搜索多个列或所有列。

【问题讨论】:

到目前为止,您做了什么来尝试调试问题?浏览器控制台是否显示任何错误?您是否尝试在调试器中单步执行您的 JS 代码? “还有 m 使用 WHERE name LIKE %$value%;但是我如何搜索多个列或所有列。” - 通过为每列添加附加条件。 (如果这不是您想要的,那么也许可以查看全文搜索。) 你有 onkeyup="myFunction()"$("#myInput").on("keyup", function() 相同的元素为什么? 不,没有错误......而且我也得到了我正确的 json 数组。 @CBroe 如果我在搜索字段中输入“luf”,这是我的回复["id":"4","name":"Luffy","mobile":"8xxxx960","description":"Decription Is As Follows","remark":"forwarded to PM","app_no":"20200516141728","status":"\u0928\u093f\u0935\u0947\u0926\u0928 \u091c\u092e\u093e","file":"","id":"9","name":"Luffy","mobile":"81xxxx0","description":"Decription Is As Follows","remark":"forwarded to PM","app_no":"20200516141728","status":"\u0928\u093f\u0935\u0947\u0926\u0928 \u091c\u092e\u093e","file":""] 【参考方案1】:
$(document).ready(function()
      $("#myInput").on("keyup", function() 
       var flag = false;
       var value = $(this).val().toLowerCase();
     $.ajax(
                    url: 'getRequestSearch.php',
                    type: 'post',
                    data: value:value,
                    dataType: 'json',

                    success:function(response)

                        var len = response.length;
                        if(len == 0)

                         else
                          var data = "";
                          var sno = 1;
                            for( var i = 0; i<len; i++)
                                var id = response[i]['id'];
                                var name = response[i]['name'];
                                var mobile = response[i]['mobile']; 
                                var description = response[i]['description']; 

                                var remark = response[i]['remark'];
                                var app_no = response[i]['app_no'];
                                var status = response[i]['status'];
                                var file = response[i]['file'];
                                if(file==""||file=="no")
                                
                                    file="blank";
                                else
                                

                                

                                    if(id=="")
                                    

                                    
                                    else
                                    
                                        data += '<tr><td data-title="Application No.">' + app_no + '</td><td data-title="ID" style="display:none;">' + id + '</td> <td class="numeric" data-title="Name">' + name + '</td><td class="numeric" data-title="Mobile">'+ mobile + '</td><td class="numeric" data-title="Description">'+ description +'</td><td class="numeric" data-title="Remark">' +remark+ '</td><td class="numeric"  data-title="Status"><span class="badge badge-primary">'+ status +'</span></td> <td class="numeric"  data-title="Download"><a class=" btn btn-success btn-sm" href="upload/request/'+file+'" target=_blank>Download</a></td><td class="numeric"  data-title="Operation"><a href="edit-request.php?sno='+id+'" onclick="return confirmation()" ><button class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i></button></a><a href="delete_request.php?sno='+id+'" onclick="return confirmation()"> <button class="btn btn-danger btn-sm"><i class="fa fa-trash-o "></i></button></a></td></tr>';  
                                    
                                    sno++;
                    $("#download-excel").attr("href", "excel-request.php?status="+status"");
                                    $("#download-excel").attr("target","_blank");
                                    $("#download-zip").attr("href", "download-zip-request.php?status="+status"");
                                    $("#download-zip").attr("target","_blank");


                            
                            $("#data").html(data)
                        



                    


                );
            );
      );

我只看到 status_sel 没有定义.. 现在它应该可以工作了

【讨论】:

应该如何工作?您在上面的代码中所做的哪些更改也添加了它? 我提到了@Swati,我所做的只是将 status_sel 更改为 status,因为未定义 var status_sel 是的,它对我有用.. status_sel 是在其他功能中定义的,因为我猜它不起作用。

以上是关于无法根据在搜索字段中输入的值显示表中的数据[关闭]的主要内容,如果未能解决你的问题,请参考以下文章

在网页上的 HTML 表中显示 MySQL 数据库表中的值

如何根据oracle中另一个表中的值更新一个表中的字段[重复]

将组合框的值作为字段传递

根据状态中的变量数显示输入字段

输入字段的值显示在控制台中但不在输入字段中+无法保存到数据库

sql根据一个字段更新另一字段