I have a MySQL table with contains a lot of trivia questions. Each entry (row) has a few columns (ID, Question #, Category, Difficulty, Question, Answer). I have a search engine set-up that queries the database like such(the HTML forms sends the search to a php script that queries the database and retrieves the info back)
search.php:
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b><em>$search</em></b> and ";
mysql_connect("mydb","notmypony","ponyrocksagain#");
mysql_select_db("quinterestdb");}
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="Answer LIKE '%$search_each%'";
else
$construct .="AND Answer LIKE '%$search_each%'";
}
$constructs ="SELECT * FROM tossups WHERE $construct";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
else
{
echo " <span class='badge badge-info'> $foundnum </span> results were found:<hr size='5'>";
$per_page = 25;
$start = $_GET['start'];
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysql_query("SELECT * FROM tossups WHERE $construct LIMIT $start, $per_page");
while($runrows = mysql_fetch_assoc($getquery))
{
$answer = $runrows ['Answer'];
$category = $runrows ['Category'];
$num = $runrows ['Question #'];
$difficulty = $runrows ['Difficulty'];
$question = $runrows ['Question'];
$round = $runrows ['Round'];
$tournament = $runrows ['Tournament'];
$year = $runrows ['Year'];
echo "<div class='alert alert-info' style='border-radius: 20px'><div style='padding: 10px'>
<span class='label label-info' font-size='30px'><em>Tournament | Year | Round | Question # | Category</em></span></div>
<b>$tournament |</b> <b>$year |</b> <b>$round |</b> <b>$num |</b> <b>$category</b>
<p><em>Question:</em> $question</p>
<div class='alert alert-info'><em><strong>ANSWER:</strong></em> $answer</div></div><hr>
";
}
My goal here is to be able to add a drop-down menu to the search form that allows the user to select a category that will restrict the results to that selected category. I'm at loss as to how to accomplish this. Any help would be greatly appreciated. I'm eager to learn. Anyways, if you're interested in viewing the project it is available here