I have made a filter function but I am having trouble with the starting table, I want all the data selected from a table to be displayed if no category is selected for the filter. So far, I can show all the necessary data needed if a category is chosen but only if a category is chosen. If none is chosen, it shows a blank table. Help please,…
Here’s the function
function listhistoryHost(){
$accountid=$_SESSION['userid'];
if(isset($_POST['button'])){
$filter=$_POST['historyfilter'];
if($filter==$filter){
$sql="select * from webhostrequest where status='$filter' order by webhostrequest.recentact desc";
$result=mysql_query($sql) or die("Error in selecting items ".mysql_error());
$out="<ul>";
while($row=mysql_fetch_array($result)){
$accountid=$row['userid'];
$requesttitle=$row['requesttitle'];
$requestid=$row['requestid'];
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\">";
echo "<tr class=\"rowcolor1\">";
echo "<td width=\"70%\"><span style=\"padding-left:20px\">Requested Web Hosting for ".$row["requesttitle"]. "</td>";
echo "<td width=\"20%\"><span style=\"padding-left:20px\">Status: " .$row["status"]. "</td>";
echo "<td>
<center>
<form id = \"form1\" method = \"post\" action = \"viewhistorywebhost.php?webhost=$requestid\">
<input type = \"submit\" name = \"button\" id = \"button\" value = \"Details\" />
</form>
</center>";
echo "</tr>";
}
echo "</table>";
return $out;
}
}
}
Here’s the form and trigger
<form id = "form1" method = "post" action = "#">
<select id="select1" name="historyfilter">
<option value='' selected disabled>Select item type</option>
<?php
$options = array('approved' => 'Approved',
'cancelled'=>'Cancelled',
'rejected' => 'Rejected');
foreach($options as $value => $type){
echo "<option value=\"$value\">$type</option>";
}
?>
</select>
<input type = "submit" name = "button" id = "submit" value = "Go" />
</form>
<?php
$webhost=new requisition2();
echo $webhost->listhistoryHost();
?>
Just put if condition for query