【问题标题】:Adding AJAX Search Filter to Results - PHP/MySQL将 AJAX 搜索过滤器添加到结果中 - PHP/MySQL
【发布时间】:2013-03-25 18:46:06
【问题描述】:

我正在尝试创建一个页面来显示我的数据库中的所有数据,但我希望能够通过搜索框实时过滤数据,消除与查询不匹配的行,几乎完全一样数据表。但是,我不能使用 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>

【问题讨论】:

    标签: php mysql search


    【解决方案1】:

    【讨论】:

    • 非常感谢。如何设置它只搜索 2 个字段,“姓名”和“电话”?
    猜你喜欢
    • 2012-03-31
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2012-06-07
    • 2011-10-18
    • 2011-06-17
    相关资源
    最近更新 更多