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.
<?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;"> </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:
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.