I have seen a lot of demos or sort of the same questions with the Select All option. But what I want is to just have a drop down that will allow me to select All option and not showing the entire Select box. Individual Select option works but not when I tried to use ALL as an option.
Here is my sample HTML:
<select name="status" id="status" style="width: 224px;">
<option value="" selected="selected">Please select...</option>
<option value="All">All</option>
<option value="Option1">Option1</option>
<option value="Option2">Option2</option>
<option value="Option3">Option3</option>
<option value="Option4">Option4</option>
</select>
From the code above I would want to filter the result using the All option.
So this is the page is where I filter and show the results in a table,
<script>
$(document).ready(function(){
$("#results").show();
});
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#RetrieveList").on('click',function() {
var status = $('#status').val();
var date = $('#Date').val();
var date1 = $('#Date1').val();
$.post('retrieve_status.php',{status:status, date:date, date1:date1}, function(data){
$("#results").html(data);
});
return false;
});
});
</script>
<form id="form2" name="form2" method="post" action="">
<table width="941" border="0" align="center">
<tr>
<th width="935" colspan="9" scope="col">Status:
<select name="status" id="status" style="width: 224px;">
<option value="" selected="selected">Please select...</option>
<option value="All">All</option>
<option value="Option1">Option1</option>
<option value="Option2">Option2</option>
<option value="Option3">Option3</option>
<option value="Option4">Option4</option>
</select>
Start Date:<input type="text" name="Date" id="Date" size="8"/>
End Date:<input type="text" name="Date1" id="Date1" size="8"/>
<input name="action" type="submit" id="RetrieveList" value="Retrieve List" />
</th>
</tr>
</table>
</form>
<div id="results">
</div>
And this is how I fetch the data,
<?php
require 'include/DB_Open.php';
$status = $_POST['status'];
$date = $_POST['date'];
$date1 = $_POST['date1'];
if ($_POST['status'] == 'ALL')
{
$sql_status = '1';
}
else
{
$sql_status = "status = '".mysql_real_escape_string($_POST['status'])."'";
}
$sql="SELECT column1, column2, status
FROM tracker
WHERE status = '" . $sql_status . "' AND scheduled_start_date BETWEEN '" . $date . "' AND '" . $date1 . "'
ORDER BY scheduled_start_date";
$myData = mysql_query($sql);
//to count if there are any results
$numrow = mysql_num_rows($myData);
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo "CRQ Count: $numrow";
}
{
echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'>
<tr>
<th align='center'><strong>Column1</strong></th>
<th align='center'><strong>Column2</strong></th>
<th align='center'><strong>Status</strong></th>
</tr>";
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve_status.php' method='post'>";
echo"<tr>";
echo "<td align='center'>" . $info['column1'] . "<input type=hidden name=column1 value=" . $info['column1'] . " </td>";
echo "<td align='center'>" . $info['column2'] . "<input type=hidden name=column2 value=" . $info['column2'] . " </td>";
echo "<td align='center'>" . $info['status'] . "<input type=hidden name=status value=" . $info['status'] . " </td>";
echo "</tr>";
echo "</form>";
}
}
echo "</table>";
include 'include/DB_Close.php';
?>