Question

Hi I want to filter my searches in the sql based on the requirement the user wants so i used a select tag and depending on the value of the select tag a certain sql statement will be used but its not working as expected can you help me looked what went wrong here:

$strFilterByStatus = $_POST['byStatus'];

<select name="byStatus" id="byStatus" onChange="frmAdminWorklist.submit()">
<option value="all">All</option>
<option value="recovered">Recovered</option>
    <option value="unrecovered">Unrecovered</option>
</select>

<?php   
    if($strFilterByStatus=='all'){
       $strSQL = "SELECT * FROM  tblcase";
       $SQL=mysql_query($strSQL);   
    }
?>

appreciate the help :)

Was it helpful?

Solution

Suppose this is all in theTest.php

<?php
    $strFilterByStatus = $_POST['byStatus'];
?>

<form id='testform" action="theTest.php" method="post">
  <select name="byStatus" id="byStatus" onChange="frmAdminWorklist.submit()">
    <option value="all">All</option>
    <option value="recovered">Recovered</option>
    <option value="unrecovered">Unrecovered</option>
  </select>
  <input type='submit' name='' value='Go test it'>
</form>

<?php   
    if ( $strFilterByStatus == 'all' )
    {
       $strSQL = "SELECT * FROM  tblcase";
       $SQL = mysql_query($strSQL);   
    }
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top