0

我需要有人向我展示如何创建一个简单的表来搜索我从该表单中插入的每一列数据。我正在寻找最简单的方法来创建一个带有可以过滤每一列的搜索框的表。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>
4

1 回答 1

0

不确定数据库的结构,但是如果您要搜索的区域是 TEXT,那么您可以将此where子句放入查询中:

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

explode(" ", $searchParams)之后,您可以通过使用然后将它们连接在一起来分解它,例如:

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

依此类推。然后您可以使用ORAND取决于您希望搜索的准确程度

于 2012-11-06T23:19:28.903 回答