无法获取要排序的PHP结果表-表包含过滤器

时间:2019-08-04 02:29:02

标签: php jquery

我已将tablesorter添加到使用过滤器的表中,但无法进行排序。我是PHP新手。如何正确设置代码?过滤功能起作用。该表已填充,并且过滤器有效,但无法进行排序。

我的代码如下。

    <?php

    if(isset($_POST['search']))
   {
    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `rm_inventory_view` WHERE 
    CONCAT(`raw_material_code`, `description`) LIKE 
'   %".$valueToSearch."%'";
    $search_result = filterTable($query);

    }
    else {
    $query = "SELECT * FROM `rm_inventory_view`";
    $search_result = filterTable($query);
    }

    // function to connect and execute the query
    function filterTable($query)
    {
    $connect = mysqli_connect("localhost", "root", "password", 
    "inventory");
    $filter_Result = mysqli_query($connect, $query);
    return $filter_Result;
    }

    ?>

    <!DOCTYPE html>
    <div id="center_button"><button 
    onclick="location.href='http://localhost/batch/'">Back to 
    Home</button> 
    </div><br>

    <html>

    <thead>
    <script type="text/javascript" src="/localhost/batch/tablesorter- 
    master/jquery-latest.js"></script> 
    <script type="text/javascript" src="/localhost/batch/tablesorter- 
    master/jquery.tablesorter.js"></script> 
    <script>
    $(document).ready(function() {
    $("#sortTable").tablesorter();
    }
    );
    </script>
    <title>rm_inventory_view</title>
    <table id="myTable" class="tablesorter">
    <thead>
    <tr>

    </tr>
    <style>
        table,tr,th,td
        {
            border: 1px solid black;
        }
     </style>
     </thead> 
     <tbody>
    <form action="rm_inventory_view_filter.php" method="post">
        <input type="text" name="valueToSearch" placeholder="Value To 
     Search"><br><br>
        <input type="submit" name="search" value="Filter"><br><br>

        <table>
            <tr>
                <th>raw_material_code</th>
     <th>description</th>

            </tr>
      <!-- populate table from mysql database -->
            <?php while($row = mysqli_fetch_array($search_result)):?>
            <tr>

      <td><?php echo $row['raw_material_code'];?></td>
      <td><?php echo $row['description'];?></td>


            </tr>
            <?php endwhile;?>

        </table>

        </form>
        <br><div id="center_button"><button 
      onclick="location.href='http://localhost/batch/'">Back to 
      Home</button> 
       </div>
     </tbody>

      </html>

没有错误出现。只是没有排序发生。

0 个答案:

没有答案