简体   繁体   English

向表列添加搜索过滤器

[英]Adding search filters to my table columns

I need someone to show me how you would create a simple table to search each column of data that I insert from this form. 我需要有人向我展示如何创建一个简单的表来搜索我从此表单插入的每一列数据。 I am looking for the easiest way to create a table with search boxes that can filter each column. 我正在寻找一种最简单的方法来创建带有可过滤每一列的搜索框的表。 DB: Mysql Field types: text Below shows the variables I am using for my form that posts the data to the database. DB:Mysql字段类型:文本下面显示了我用于表单的变量,这些变量用于将数据发布到数据库。

<?php

if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
    for ($count = 1; $count <= 9; $count++)
    {
        $fields[$count] = "";
        if (isset($_POST["field" . $count . ""]))
        {
            $fields[$count] = trim($_POST["field" . $count . ""]);
            //echo $fields[$count] . "<br />";
        }
    }

    $con = mysql_connect("local", "user", "pass");
    mysql_select_db("DB", $con);

    $fromzip = mysql_real_escape_string($_POST['fromzip']);
    $tozip = mysql_real_escape_string($_POST['tozip']);

    $insert = "INSERT INTO Carriers (`fromzip` ,`tozip` ,`date`) VALUES('$fromzip' ,'$tozip' , NOW())";
    mysql_query($insert) or die(mysql_error());

    $select = "SELECT `fromzip` ,`tozip` , FROM `Carriers` ORDER BY `date` DESC;";
    $result = mysql_query($select) or die(mysql_error());

}
?>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<div
 style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
  <div
  style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
  <table style="font-weight: normal; width: 100%; font-size: 12px;"
 border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
   <table
 style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
 border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
    <tbody>
            <tr>
              <td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
 style="width: 100%;" type="text">
        </tr>
        <tr>
              <td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
 style="width: 100%;" type="text">
        </tr>
        </tbody>
  </table>
  <p style="text-align: center;"><input name="submit" value="Submit"
 class="submit" type="submit"></p>
  </div>
</form>
</div>
<p style="margin-bottom: -20px;">&nbsp;</p>
</body>

Not sure of the structure of the database, but if the area you want to search from is a TEXT, then you can put this where clause into you query: 不确定数据库的结构,但是如果要从中搜索的区域是TEXT,则可以将此where子句放入查询中:

SELECT * FROM `Carriers` WHERE `carriername` LIKE '%{searchParams}%' ORDER BY date DESC, paymentamount ASC

After that, you could break it down by using explode(" ", $searchParams) and then concatenating them together like: 之后,您可以使用explode(" ", $searchParams)将其分解,然后将它们串联在一起,如下所示:

SELECT * FROM `Carriers` WHERE `carriername` LIKE '%{searchParams[0]}%' OR `carriername` LIKE '%{searchParams[1]}%' ORDER BY date DESC, paymentamount ASC

and so on for each item. 以此类推。 Then you could use OR or AND depending on how accurate you want the search to be 然后,您可以使用ORAND具体取决于您希望搜索的准确性如何

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

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