Hi guys I’m new to this site and i really need a professional help out here. I am trying to make a search form in my page and basically i can search my database already but i need to revised the code because the process of my search form depends on a dropdown menu
which contains the table names in my database basically the searching will depend to the selected service form the dropdown menu. what i want to happen is to** eliminate the dropdown menu and make an automatic searching throughout my tables in the database and fetch the necessary data.. thanks in advance
**
this is the searchform.html

<html>
<body bgcolor="#CCCCCC">
 <form method="post" action="searchresult.php" name="form2">
   <p><img src="images/europcar.jpg" width="560" height="162" /></p>
   <p align="center">Please dont live any blank space while searching</p>
   <p align="center">Search Reservation Number </p>
   <p align="center">
     <input type="text" name="search" size=25 maxlength=25 >   
      <select name="table" size="1">
        <option selected="selected"></option>
        <option value="sd">SelfDrive</option>
         <option value="sdti">SelfDrive texas</option>
        <option value="ch">Carhire</option>
          <option value="chti">Carhire texas</option>
           <option value="cd">Chauffeur Drive</option>
            <option value="cdti">Chauffeur Drive texas</option>
            <option value="pudo">Pick up Drop off</option>
            <option value="pudoti">Pick up Drop off texas</option>

       </select>
     <input type="Submit" name="Submit" value="Submit">
     </p>
 </form>
</body>
 </html>


**this part is the searching
searchresult.php**

<?php
   $table=$_POST['table'];
   $search=$_POST['search'];


 if ($search == "" or $table=="") 
 { 
 echo"<a href='a.html'> back </a>";
 echo "<p>You forgot to enter the reservation number"; 
 exit; 
 } 

$dbhost = 'localhost';
$dbuser = 'europcar_msic';
$dbpass = 'msictran';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'europcar_msic';
mysql_select_db($dbname);








if ($table=="cd")
{



 $sql = mysql_query("select * from cd where Rnum like '$search'");


}
if ($table=="sd")
{


 $sql = mysql_query("select * from sd where Rnum like '$search'");

}
if ($table=="ch")
{


 $sql = mysql_query("select * from ch where Rnum like '$search'");

}
if ($table=="pudo")
{


 $sql = mysql_query("select * from pudo where Rnum like '$search'");

}
if ($table=="sdti")
{



 $sql = mysql_query("select * from sdtexas where Rnum like '$search'");


}
 if ($table=="chti")
{



 $sql = mysql_query("select * from chtexas where Rnum like '$search'");


}
if ($table=="cdti")
{



 $sql = mysql_query("select * from cdtexas where Rnum like '$search'");


}

if ($table=="pudoti")
{



 $sql = mysql_query("select * from pudotexas where Rnum like '$search'");


}



while ($row=mysql_fetch_array($sql))
{
                                echo " <table width='100%' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#CCCCCC' >  ";
                                echo " <tr bgcolor='green'>";
                                echo " <td width='5%' align='center' height='10' ><p><font color='white'><strong><B>Reservation Number </th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Name</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Vehicle Type</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Origin</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Pick up date</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Time</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Destination</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b>Return Date</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b> Return Time</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b> Contact Number</th>";
                                echo "<td width='5%' align='center' height='10' ><p><font color='white'><b> Address</th>";
                                echo "</tr>";


                               echo"<tr>";
                               echo"<a href='a.html'> back </a>";
                             echo"<tr>";
                                        echo "<td width='5%' align='center' height='10' > $row[Rnum]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Fname] $row[Lname]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Vehicle]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Origin]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Pickday] $row[Pickmonth]   </td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Pickhour] : $row[Pickmin]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Destination]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Rday] $row[Rmonth]   </td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Rhour] : $row[Rmin]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Contact]</td>";
                                        echo "<td width='5%' align='center' height='10' >$row[Zip],$row[Address],$row[City] $row[Country]</td>";
                               echo '<br/><br/>';
  } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($sql); 
 if ($anymatches == 0) 

    { 
    echo"<a href='searchform.html'> back </a>";
   echo "Sorry,Invalid Reservation Number or you are looking at the wrong place double check the number and search it again"; 
    } 

   {


}

 ?>

If the tables structeres are the same then you can use UNION, something like:

SELECT * FROM table1 WHERE condition = 'this' UNION SELECT * FROM table2 WHERE condition = 'this';

But if the tables are the same you will get a better performance if you merge them in a single table and create an index. http://dev.mysql.com/doc/refman/5.0/en/union.html

hi cereal am i doing it correctly?

$sql = mysql_query("select * from sdti where Rnum like '$search'") UNION ("select * from sd where Rnum like '$search'") UNION ("select * from tr where Rnum like '$search'") ;

hey i got ot working already!

Good to know you got it working, its more of an SQL and the use of JOIN query issue than it is PHP. I would advice you to read extensively about the topic, it makes an interesting read especially if you plan to venture into frameworks like YII Framework.