簡體   English   中英

將AJAX搜索過濾器添加到結果-PHP / MySQL

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

我正在嘗試創建一個頁面,以顯示數據庫中的所有數據,但是我希望能夠通過搜索框實時過濾數據,從而消除與查詢不匹配的行,幾乎完全像DataTables。 但是,我無法使用DataTables,因為我很難添加自己的自定義列。 我知道如何制作一個顯示結果的搜索頁面,但不知道如何在結果中搜索。

任何幫助,將不勝感激。 謝謝。

<!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