简体   繁体   English

将AJAX搜索过滤器添加到结果-PHP / MySQL

[英]Adding AJAX Search Filter to Results - PHP/MySQL

I'm trying to create a page that displays all the data from my database, but I'd like the ability to live filter the data through a search box, eliminating rows that don't match the query, almost exactly like DataTables. 我正在尝试创建一个页面,以显示数据库中的所有数据,但是我希望能够通过搜索框实时过滤数据,从而消除与查询不匹配的行,几乎完全像DataTables。 I can't use DataTables, however, because I'm finding it difficult to add the custom columns I have. 但是,我无法使用DataTables,因为我很难添加自己的自定义列。 I know how to make a search page that then displays results but not how to search within results. 我知道如何制作一个显示结果的搜索页面,但不知道如何在结果中搜索。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php

        // connect to the database
        include('connect-db.php');


        // get results from database
        $result = mysql_query("SELECT * FROM Orders") 
                or die(mysql_error());      

        // display data in table        
        echo "<table border='1' cellpadding='10'>";
        echo "<tr> <th>Date</th> <th>Name</th> <th>Phone</th> <th>Location</th> <th></th> <th></th></tr>";

        while($row = mysql_fetch_array( $result )) {
     $src = '';
     switch( $row['Location'] ) {
          case '1':
              $src = '1.jpg';
              break;
          case '2':
              $src = '2.jpg';
              break;
          default:
              $src = 'default.jpg';

            }      // echo out the contents of each row into a table
                echo "<tr>";
                echo '<td>' . $row['date'] . '</td>';
                echo '<td>' . $row['Name'] . '</td>';
                echo '<td>' . $row['Phone'] . '</td>';
                echo '<td><img src="'.$src.'"></td>';
                echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
                echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
                echo "</tr>"; 
        } 

        // close table>
        echo "</table>";


?>
<p><a href="new.php">Add a new record</a></p>

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM