Hello,
I'm using a form to query a Mysql database. This form contains 1 group of radio buttons called R1. The code for the form(form1) & the form processor is below. Everything is working fine.
Now, I want to add another 2 groups of radio buttons to my form called radiobutton1 and radiobutton2. The code for the new form(form2) is below. My problem is I don't know how to write the code for the form processor. I believe that I must change the switch in the form processor to an array in order to simplify the code. I don't know how to write the array.
Additional info - the databases cannot be consolidated into 1 database with many tables because they(the databases) are very big. My webhost does not allow any individual database to exceed 50 MB.
Thanks a lot for your help.
Code for Form1:-
<form name="form1" method="POST" action="">
<tr>
<td><div align="center">
<input type="radio" value="kl06" name="R1">
Kuala Lumpur 2006<strong> or
<input name="R1" type="radio" value="sl06">
</strong>Selangor 2006<strong> or
<input name="R1" type="radio" value="kl07">
</strong>Kuala Lumpur 2007<strong> or
<input name="R1" type="radio" value="sl07" checked>
</strong>Selangor 2007 </div></td>
</tr>
<tr>
<td><div align="center">Key in Your Search Criteria Below </div></td>
</tr>
<tr>
<td><div align="center">
<input type="text" name="Text_Box_1" size="20" tabindex="6">
<strong>or</strong>
<input type="text" name="Text_Box_2" size="20" tabindex="7">
<strong>or</strong>
<input type="text" name="Text_Box_3" size="20" tabindex="8">
<strong>or</strong>
<input type="text" name="Text_Box_4" size="20" tabindex="9">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="text" name="Text_Box_5" size="20" tabindex="10">
<strong>or</strong>
<input type="text" name="Text_Box_6" size="20" tabindex="11">
<strong>or</strong>
<input type="text" name="Text_Box_7" size="20" tabindex="12">
<strong>or</strong>
<input type="text" name="Text_Box_8" size="20" tabindex="13">
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="submit" type="submit" id="submit2" value="Submit" tabindex="14">
<input name="reset2" type="reset" id="reset2" value="Reset" tabindex="15">
</div></td>
</tr>
</form>
Code for Form Processor:-
switch($_POST['R1'])
{
case 'sl06':
$username="something1";
$password="samestuff";
$database="database1";
$host="localhost";
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query="SELECT * FROM selangor WHERE (address like '%$Text_Box_1%') OR (address like '%$Text_Box_2%') OR (address like '%$Text_Box_3%') OR (address like '%$Text_Box_4%') OR (address like '%$Text_Box_5%') OR (address like '%$Text_Box_6%') OR (address like '%$Text_Box_7%') OR (address like '%$Text_Box_8%') OR (name like '%$Text_Box_1%') OR (name like '%$Text_Box_2%') OR (name like '%$Text_Box_3%') OR (name like '%$Text_Box_4%') OR (name like '%$Text_Box_5%') OR (name like '%$Text_Box_6%') OR (name like '%$Text_Box_7%') OR (name like '%$Text_Box_8%') OR (phone like '%$Text_Box_1%') OR (phone like '%$Text_Box_2%') OR (phone like '%$Text_Box_3%') OR (phone like '%$Text_Box_4%') OR (phone like '%$Text_Box_5%') OR (phone like '%$Text_Box_6%') OR (phone like '%$Text_Box_7%') OR (phone like '%$Text_Box_8%') LIMIT 0, 15";
break;
case 'kl06':
$username="something2";
$password="samestuff";
$database="database2";
$host="localhost";
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query="SELECT * FROM wilayah WHERE (address like '%$Text_Box_1%') OR (address like '%$Text_Box_2%') OR (address like '%$Text_Box_3%') OR (address like '%$Text_Box_4%') OR (address like '%$Text_Box_5%') OR (address like '%$Text_Box_6%') OR (address like '%$Text_Box_7%') OR (address like '%$Text_Box_8%') OR (name like '%$Text_Box_1%') OR (name like '%$Text_Box_2%') OR (name like '%$Text_Box_3%') OR (name like '%$Text_Box_4%') OR (name like '%$Text_Box_5%') OR (name like '%$Text_Box_6%') OR (name like '%$Text_Box_7%') OR (name like '%$Text_Box_8%') OR (phone like '%$Text_Box_1%') OR (phone like '%$Text_Box_2%') OR (phone like '%$Text_Box_3%') OR (phone like '%$Text_Box_4%') OR (phone like '%$Text_Box_5%') OR (phone like '%$Text_Box_6%') OR (phone like '%$Text_Box_7%') OR (phone like '%$Text_Box_8%') LIMIT 0, 15";
break;
case 'sl07':
$username="something3";
$password="samestuff";
$database="database3";
$host="localhost";
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query="SELECT * FROM selangor WHERE (address like '%$Text_Box_1%') OR (address like '%$Text_Box_2%') OR (address like '%$Text_Box_3%') OR (address like '%$Text_Box_4%') OR (address like '%$Text_Box_5%') OR (address like '%$Text_Box_6%') OR (address like '%$Text_Box_7%') OR (address like '%$Text_Box_8%') OR (name like '%$Text_Box_1%') OR (name like '%$Text_Box_2%') OR (name like '%$Text_Box_3%') OR (name like '%$Text_Box_4%') OR (name like '%$Text_Box_5%') OR (name like '%$Text_Box_6%') OR (name like '%$Text_Box_7%') OR (name like '%$Text_Box_8%') OR (phone like '%$Text_Box_1%') OR (phone like '%$Text_Box_2%') OR (phone like '%$Text_Box_3%') OR (phone like '%$Text_Box_4%') OR (phone like '%$Text_Box_5%') OR (phone like '%$Text_Box_6%') OR (phone like '%$Text_Box_7%') OR (phone like '%$Text_Box_8%') LIMIT 0, 15";
break;
case 'kl07':
$username="something4";
$password="samestuff";
$database="database4";
$host="localhost";
mysql_connect ("$host","$username","$password");
mysql_select_db($database) or die( "Where's the database man?");
$query="SELECT * FROM wilayah WHERE (address like '%$Text_Box_1%') OR (address like '%$Text_Box_2%') OR (address like '%$Text_Box_3%') OR (address like '%$Text_Box_4%') OR (address like '%$Text_Box_5%') OR (address like '%$Text_Box_6%') OR (address like '%$Text_Box_7%') OR (address like '%$Text_Box_8%') OR (name like '%$Text_Box_1%') OR (name like '%$Text_Box_2%') OR (name like '%$Text_Box_3%') OR (name like '%$Text_Box_4%') OR (name like '%$Text_Box_5%') OR (name like '%$Text_Box_6%') OR (name like '%$Text_Box_7%') OR (name like '%$Text_Box_8%') OR (phone like '%$Text_Box_1%') OR (phone like '%$Text_Box_2%') OR (phone like '%$Text_Box_3%') OR (phone like '%$Text_Box_4%') OR (phone like '%$Text_Box_5%') OR (phone like '%$Text_Box_6%') OR (phone like '%$Text_Box_7%') OR (phone like '%$Text_Box_8%') LIMIT 0, 15";
}
Code for Form2:-
<form name="form2" method="post" action="">
<tr>
<td><div align="center">
<input type="radio" value="kl06" name="R1">
Kuala Lumpur 2006<strong> or
<input name="R1" type="radio" value="sl06">
</strong>Selangor 2006<strong> or
<input name="R1" type="radio" value="kl07">
</strong>Kuala Lumpur 2007<strong> or
<input name="R1" type="radio" value="sl07" checked>
</strong>Selangor 2007</div></td>
</tr>
<tr>
<td><div align="center">Key in Your Search Criteria Below</div></td>
</tr>
<tr>
<td><div align="center">Search by
<input name="Text_Box_1" type="text" id="Text_Box_1" tabindex="6" value="Name" size="15">
<label>
<input name="radiobutton1" type="radio" value="and">
<strong>and</strong></label>
<input name="radiobutton1" type="radio" value="or" checked>
<strong>or </strong>
<input name="Text_Box_2" type="text" id="Text_Box_2" tabindex="7" value="Phone" size="15">
<label>
<input name="radiobutton2" type="radio" value="and">
<strong>and</strong></label>
<input name="radiobutton2" type="radio" value="or" checked>
<strong>or </strong>
<input name="Text_Box_3" type="text" id="Text_Box_3" tabindex="8" value="Address" size="15">
</div></td>
</tr>
<tr>
<td><div align="center">
<input name="submit" type="submit" id="submit" value="Submit" tabindex="14">
<input name="reset22" type="reset" id="reset22" value="Reset" tabindex="15">
</div></td>
</tr>
</form>