I'd like to have a search and textbox filter for my site. The search would search for the name of a place and location while the checkbox would filter a activity. Right now I have a working search and a working checkbox filter but can not figure out how to combine them. I'd really appreciate any help or links to tutorials etc as I'm still learning both languages and only recently started struggling and am now at a complete standstill.
Here's the PHP
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){
$name=$_POST['name'];
//connect to the database
$db=mysql_connect ("dbhost", "dbo560757688", "pw") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("db560757688");
// Fruits
$fruits = array();
foreach($_POST['fruit'] as $fruit) {
$fruit = mysql_real_escape_string($fruit);
$fruits[] = "'{$fruit}'";
//-query the database table
$sql="SELECT ID, FirstName, LastName, Email FROM Contacts WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%' WHERE Activity LIKE (" . implode(", ", $fruits) . "";
//-run the query against the mysql query function
$result=mysql_query($sql);
// Table Poop
echo "<table border=1>
<tr>
<th>Name
</th>
<th>
Last Name
</th>
<th>
Activity
</th>";
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName=$row['FirstName'];
$LastName=$row['LastName'];
$Activity=$row['Activity'];
$Email=$row['Email'];
//-display the result of the array
echo "<tr>";
echo "<td>".$FirstName."</td>";
echo "<td>".$LastName."</td>";
echo "<td>".$Activity."</td>";
echo "</tr>";
}
}
}
else
echo "<p>Please enter a search query</p>";
}
}
?>
Aucun commentaire:
Enregistrer un commentaire