Briefly: I am doing an advanced search page for a movie review website.
Objective: To reflect results according to selected specific parameter(s) with a single search button.
Question: How do I condition the search process page to enable 'searchby' specific parameters? Include array? Set boolean??
E.g. If I fill in the blank for title and select a date (leaving the rest blank), I will see the result of similar titles and dates. Conversely, if i leave the title column blank, select the date range and a rating (5); I will see only the result of movies rated 5 and range between the stated dates.
Currently:
I have a main page - Search.php and four other process pages which should be combined into one.. but I can't do it without errors...
- p_search.php which searches by title or director
- p_searchdate.php which searches by release date between --- to ---
- p_searchrate.php which searches for movie by star ratings 1 - 5
- p_searchur.php which searches for movie by average user ratings 1 -5)
HELP! 🙁
This is search.php ...
<H1><center> Advanced Search</H1>
<table width="800" border="1" align="center" cellpadding='5' cellspacing='5'>
<form name="search" method="POST" action="p_search.php">
<tr>
<td align="left">
Looking for <input name="search" type="text"><select name="searchby" size="1" id="searchby">
<option value="title" selected> Title </option>
<option value="Director"> Director </option>
</td>
</tr>
<form name="Release_date" method="POST" action="p_searchdate.php">
<SCRIPT LANGUAGE="JavaScript" SRC="CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
<tr>
<td align="left">
Release Date between
<input name="Release_date" id="Release_date" type="text" value="" align="right"> <A HREF="#"
onClick="cal.select(document.forms['Release_date'].Release_date,'anchor1','yyyy/MM/dd'); return false;"
NAME="anchor1" ID="anchor1"><font size=1.5>[Date]</font></A> --- <input name="Release_date2" id="Release_date2" type="text" value="" align="right"> <A HREF="#"
onClick="cal.select(document.forms['Release_date'].Release_date2,'anchor2','yyyy/MM/dd'); return false;"
NAME="anchor2" ID="anchor2"><font size=1.5>[Date]</font></A>
</td>
</tr>
<form name="rating" method="POST" action="p_searchrate.php">
<tr>
<td align="left">
Official Rating
<input type="radio" name="rating" value="1"><img src='images/star2.gif'>
<input type="radio" name="rating" value="2"><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="rating" value="3"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="rating" value="4"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="rating" value="5"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
</tr>
<tr>
</tr>
<form name="userrating" method="POST" action="p_searchur.php">
<tr>
<td align="left">
Average User Rating
<input type="radio" name="userrating" value="1"><img src='images/star2.gif'>
<input type="radio" name="userrating" value="2"><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="userrating" value="3"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="userrating" value="4"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
<input type="radio" name="userrating" value="5"><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'><img src='images/star2.gif'>
</tr>
<tr>
<td align="left">
<input type="submit" name="Submit" value="search">
</tr>
</form>
</table>
This is p_search.php
$searchQur = trim($_POST['search']);
$var=$searchQur;
$searchby =$_POST['searchby'];
if (empty($var))
{
echo '<p align="center">';
echo '<meta http-equiv="Refresh" content="1;url=search.php">';
echo 'Invalid Search. Please fill in the blank.';
echo '</p>';
}
elseif($searchby=='title')
{
$gettitle= "SELECT distinct * from movie WHERE publish=1 AND title LIKE '%".$searchQur."%'ORDER BY movie_id";
$result = mysql_query($gettitle) or die (mysql_error());
if(mysql_num_rows($result)>0)
{
echo "Search results:<br><br>";
echo "<table border='1'>";
echo "<tr>";
echo "<td width='150'>Title</td>";
echo "<td width='200'>Image</td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
$movie_id=$row['movie_id'];
$title =$row['title'];
$imageurl =$row['imageurl'];
echo "<tr bgcolor=#ddeeff>";
echo"<td><a href='detail2.php?id=$movie_id'>$title</td>";
echo"<td><img src='picture/$imageurl' width='200'/></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo '<p align="center">';
echo '<meta http-equiv="Refresh" content="1;url=search.php">';
echo "T: No result founds. Please try again.";
echo '</p>';
}
}
elseif($searchby=='Director')
{
$getDirector="SELECT distinct * from movie WHERE publish=1 AND Director LIKE '%".$searchQur."%'ORDER BY movie_id";
$result2 = mysql_query($getDirector) or die (mysql_error());
if(mysql_num_rows($result2)>0)
{
echo "Search results:<br><br>";
echo "<table border='1'>";
echo "<tr>";
echo "<td width='150'>Director</td>";
echo "<td width='150'>Title</td>";
echo "<td width='200'>Image</td>";
echo "</tr>";
while($row = mysql_fetch_array($result2)){
$movie_id=$row['movie_id'];
$Director=$row['Director'];
$title =$row['title'];
$imageurl =$row['imageurl'];
echo "<tr bgcolor=#ddeeff>";
echo"<td>$Director</td>";
echo"<td><a href='detail2.php?id=$movie_id'>$title</td>";
echo"<td><img src='picture/$imageurl' width='200'/></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo '<p align="center">';
echo '<meta http-equiv="Refresh" content="1;url=search.php">';
echo "D: No result found. Please try again";
echo '</p>';
}
}
This is p_searchdate.php
$searchQur = trim($_POST['Release_date']);
$Release_date=date("Y/m/d",strtotime($searchQur));
$searchQur2 = trim($_POST['Release_date2']);
$Release_date2=date("Y/m/d",strtotime($searchQur2));
if($Release_date!='' || $Release_date2!='')
{
$result3 = mysql_query("Select * from movie WHERE (publish=1) AND (Release_date <='$searchQur2') AND (Release_date >'$searchQur') order by Release_date ASC")or die(mysql_error());
if(mysql_num_rows($result3)>0)
{
echo "Search results:<br><br>";
echo "<table border='1'>";
echo "<tr>";
echo "<td width='150'>Director</td>";
echo "<td width='90'>Release Date</td>";
echo "<td width='150'>Title</td>";
echo "<td width='200'>Image</td>";
echo "</tr>";
while($row = mysql_fetch_assoc($result3)){
$movie_id=$row['movie_id'];
$Director=$row['Director'];
$Release_date = $row['Release_date'];
$title =$row['title'];
$imageurl =$row['imageurl'];
echo"<tr bgcolor=#ddeeff>";
echo"<td><center>$Director</td>";
echo"<td><center>".date("d/m/Y",strtotime($Release_date))."</td>";
echo"<td><center><a href='detail2.php?id=$movie_id'>$title</td>";
echo"<td><img src='picture/$imageurl' width='200'/></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo '<p align="center">';
echo '<meta http-equiv="Refresh" content="1;url=search.php">';
echo "Date: No results found.";
echo '</p>';
}
}