Multiple Drop down list to filter MySQL Tables

Codes here !

Moderators: macek, egami, gesf

kelvin24
New php-forum User
New php-forum User
Posts: 12
Joined: Mon Aug 13, 2012 5:11 pm

Multiple Drop down list to filter MySQL Tables

Postby kelvin24 » Wed Aug 15, 2012 6:22 pm

I want to filter my table in MySQL by many categories but once I'd finished the other drop down list the IF statements of the first Drop down was not able to filter the table. The If Statement of the second filter was the one recognized. Here's the code.Please :help:

Code: Select all

<div>
   <form <?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter'><br /><br />
    <select name="Dlrdrop">
       <option value="Alldlr">Dealer</option>
        <option value="HGH">HGH</option>
        <option value="HBI">HBI</option>
   </select><input type='submit' value = 'Filter'>
           <select name="Monthdrop">
     <option value="Month">Month</option>
     <option value="January">January</option>
     <option value="February">February</option>
     <option value="March">March</option>
     <option value="April">April</option>
     <option value="May">May</option>
     <option value="July">June</option>
     <option value="August">August</option>
     <option value="September">September</option>
     <option value="October">October</option>
     <option value="November">November</option>
     <option value="December">December</option>
   </select>
    <input type='submit' value = 'Filter' />
   <form <?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter'>
   <br /><br /><br /><br /><br /><br />
</div>
<?php
$username = "root";
$password = "kelvin";
$hostname = "localhost";
$value= $_POST["Dlrdrop" or "Monthdrop"];




$dbhandle = @mysql_connect($hostname, $username, $password) or die("Could not connect to database");
@mysql_select_db("softeng", $dbhandle) or die("No database");

if($_POST['Dlrdrop'] == 'Alldlr'){
   $sql = "SELECT * FROM records";
   }
elseif($_POST['Dlrdrop'] == 'HGH'){
   $sql = "SELECT * FROM records WHERE Dealer='HGH'";
   
   }
elseif($_POST['Dlrdrop'] == 'HBI'){
   $sql = "SELECT * FROM records WHERE Dealer='HBI'";
   }
if($_POST['Monthdrop'] == 'Month'){
   $sql = "SELECT * FROM records";
   }
elseif($_POST['Monthdrop'] == 'January'){
   $sql = "SELECT * FROM records WHERE Month='January'";
   }
elseif($_POST['Monthdrop'] == 'February'){
   $sql = "SELECT * FROM records WHERE Month='February'";
   }
elseif($_POST['Monthdrop'] == 'March'){
   $sql = "SELECT * FROM records WHERE Month='March'";
   }
elseif($_POST['Monthdrop'] == 'April'){
   $sql = "SELECT * FROM records WHERE Month='April'";
   }   
elseif($_POST['Monthdrop'] == 'May'){
   $sql = "SELECT * FROM records WHERE Month='May'";
   }   
elseif($_POST['Monthdrop'] == 'June'){
   $sql = "SELECT * FROM records WHERE Month='June'";
   }   
      
elseif($_POST['Monthdrop'] == 'July'){
   $sql = "SELECT * FROM records WHERE Month='July'";
   }   
      
elseif($_POST['Monthdrop'] == 'August'){
   $sql = "SELECT * FROM records WHERE Month='August'";
   }   
      
elseif($_POST['Monthdrop'] == 'September'){
   $sql = "SELECT * FROM records WHERE Month='September'";
   }   
      
elseif($_POST['Monthdrop'] == 'October'){
   $sql = "SELECT * FROM records WHERE Month='October'";
   }   
      
elseif($_POST['Monthdrop'] == 'November'){
   $sql = "SELECT * FROM records WHERE Month='November'";
   }   
      
elseif($_POST['Monthdrop'] == 'December'){
   $sql = "SELECT * FROM records WHERE Month='December'";
   }   
      
$mytab =  @mysql_query($sql) or die ("Could not FILTER");

$myData = @mysql_query($sql,$dbhandle) or die ("Can not fetch data");
echo "<center><table border=1 width=300%>
<tr>
   
   <th align=center width=200>Referrence No</th>
   <th align=center width=100px>Date</th>
   <th width=50px align=center>Dealer</th>
   <th align=center width=120px>Repair Order</th>
   <th align=center width=150>Parts Issuance Slip</th>
   <th align=center width=150>Service Invoice</th>
   <th align=center width=120>Engine Oil Type</th>
   <th align=center width=150>No of Liters Sold</th>
   <th align=center width=220>Service Advisor/Parts Man</th>
   <th align=center width=100>Incentive Amount</th>
   <th align=center width=220>Technician</th>
   <th align=center width=100>Incentive Amount</th>
   <th align=center width=220>Service Manager</th>
   <th align=center width=100>Incentive Amount</th>
   <th align=center width=220>Parts Manager</th>
   <th align=center width=100>Incentive Amount</th>
   <th align=center width=100>Total Amount</th>
   
</tr>";
while($record = @mysql_fetch_array($myData)){
echo "<tr>";
echo "<td align=center>" . $record['Referrence No'] . "</td>";
echo "<td align=center>" . $record['Date'] . "</td>";
echo "<td align=center>" . $record['Dealer'] . "</td>";
echo "<td align=center>" . $record['Repair Order'] . "</td>";
echo "<td align=center>" . $record['Parts Issuance Slip'] . "</td>";
echo "<td align=center>" . $record['Service Invoice'] . "</td>";
echo "<td align=center>" . $record['Engine Oil Type'] . "</td>";
echo "<td align=center>" . $record['No of Liters Sold'] . "</td>";
echo "<td align=center>" . $record['Service Advisor/Parts Man'] . "</td>";
echo "<td align=center>" . $record['Incentive_SAPM'] . "</td>";
echo "<td align=center>" . $record['Technician'] . "</td>";
echo "<td align=center>" . $record['Incentive_Tech'] . "</td>";
echo "<td align=center>" . $record['Service Manager'] . "</td>";
echo "<td align=center>" . $record['Incentive_SM'] . "</td>";
echo "<td align=center>" . $record['Parts Manager'] . "</td>";
echo "<td align=center>" . $record['Incentive_PM'] . "</td>";
echo "<td align=center>" . $record['Total Amount'] . "</td>";



echo "</tr>";

}



echo '</table></center>';


mysql_close($con);


?>

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests