Hi there,
I am looking for help to code a php mysql search form with 4 dropdown list. I want the user to search for accommodation establishments by using a citytown, tourism route, accommodation profile and accommodation tariffs. All this will be in the dropdown list which reflects the fields in the database table users
. I can connect to the database but cannot get my head around how to code the php script to get results for all fopur fields from the database. Also if the users only select one, two or three of the dropdown lists how do I code that the specific result is only returned in the search.
Woiuld appreciate if anyone can point me in the right direction for me to strat learning. herewith my code so far:
<?php
include 'dbc.php';
include 'classes/selectbox.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="myform" id="myform">
<h2>Search Accommodation:</h2>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="3" class="forms">
<tr>
<td>CityTown<span class="required">*</span><br />
<?php
$mybox = new SelectionBox();
//This is the name of the selection box
$mybox->SetName("citytown");
//This is how to set an option and its value
$mybox->SetOption("Jeffreys Bay","Jeffreys Bay");
$mybox->SetOption("St Francis Bay","St Francis Bay");
$mybox->SetOption("Port Elizabeth","Port Elizabeth");
$mybox->SetOption("Cape St Francis","Cape St Francis");
$mybox->SetOption("Humansdorp","Humansdorp");
$mybox->SetOption("Oyster Bay","Oyster Bay");
//Finally, we output the box and specify which option value we want selected
$mybox->CreateBox("citytown");
?></td></tr>
<tr>
<td>Tourism Route<span class="required">*</span><br />
<?php
$mybox = new SelectionBox();
//This is the name of the selection box
$mybox->SetName("tourism_route");
//This is how to set an option and its value
$mybox->SetOption("Kouga Tourism Route","Kouga Tourism Route");
$mybox->SetOption("Tsitsikamma Tourism Route","Tsitsikamma Tourism Route");
$mybox->SetOption("Sunshine Coast","Sunshine Coast");
$mybox->SetOption("Greater Addo Route","Greater Addo Route");
//Finally, we output the box and specify which option value we want selected
$mybox->CreateBox("tourism_route");
?> </td>
</tr>
<tr>
<td>Acc Category<span class="required">*</span><br />
<?php
$mybox = new SelectionBox();
//This is the name of the selection box
$mybox->SetName("acc_category");
//This is how to set an option and its value
$mybox->SetOption("Bed & Breakfast","Bed & Breakfast");
$mybox->SetOption("Guest House","Guest House");
$mybox->SetOption("Selfcatering","Selfcatering");
$mybox->SetOption("Hotel","Hotel");
$mybox->SetOption("Lodge","Lodge");
$mybox->SetOption("Backpacker","Backpacker");
//Finally, we output the box and specify which option value we want selected
$mybox->CreateBox("acc_category");
?></td></tr>
<tr>
<td>Accommodation Tariffs<span class="required">*</span><br />
<?php
$mybox = new SelectionBox();
//This is the name of the selection box
$mybox->SetName("acc_tariffs");
//This is how to set an option and its value
$mybox->SetOption("R0 - R350.00","R0 - R350.00");
$mybox->SetOption("R350.00 - R550.00","R350.00 - R550.00");
$mybox->SetOption("R550.00 - R850.00","R550.00 - R850.00");
$mybox->SetOption("R850.00 - R1 000.00","R850.00 - R1 000.00");
//Finally, we output the box and specify which option value we want selected
$mybox->CreateBox("acc_tariffs");
?></td></tr>
<tr>
<td>
<input name="submit" type="submit" value="Search"/>
</p>
</td>
</tr>
</table>
</form>
</body>
</html>
Also herewith the php class for the dropdown lists I am using:
<?php
/**
SelectionBox class
*/
class SelectionBox
{
function SetName($name)
{
$this->myname = $name;
}
function SetOption($optionvalue,$optionname)
{
$this->options[$optionname]=$optionvalue;
}
function CreateBox($selected)
{
if($this->options)
{
print "<SELECT name='".$this->myname."'>\n";
//Create Options
foreach($this->options as $optionname=>$optionvalue)
{
print "<OPTION value ='$optionvalue'";
//Check if option should be selected
if($selected == $optionvalue)
{
print "SELECTED";
}
print ">$optionname</OPTION>\n";
}
print "</SELECT>";
}
else
{
print "Error: No options specified";
}
}
}
/*
$mybox = new SelectionBox();
//This is the name of the selection box
$mybox->SetName("MySelectionBox");
//This is how to set an option and its value
$mybox->SetOption("EU","Europe");
$mybox->SetOption("IN","India");
$mybox->SetOption("MX","Mexico");
//Finally, we output the box and specify which option value we want selected
$mybox->CreateBox("MX");
*/
?>