I edited the post for a better understanding. This is my first project as a student-trainee. It is an equipment monitoring system that keeps a record of computer equipment. This
I am sharing with you guys the working code:
<label style="font-size:20px;"><strong>Filter Result:</strong></label>
<?php
$state=$_SESSION['state'];
$condition=$_SESSION['condition'];
echo "<label style='color:red;'>"." "."State:"." ".$state." "."-"."
"."Condition:"." ".$condition."</label>";
?>
<br>
<div class="filters">
<?php
}
?>
<script>
function handleRadio(data){
window.location="sessionstate.php?state="+data.value;
}
function handleRadiocond(data2){
window.location="sessioncondition.php?condition="+data2.value;
}
</script>
The rest of the code is here.
switch($state AND $condition)
will evaluate to true or false depending of the values $state
and $condition
.
So the only useful cases then are
case true
case false
case default
In your case you should use if / else construct.
Because asked in the comments how to write the conditions anyway in a switch construct see the nested code here:
switch ($state)
{
case "allstate":
if ($condition == "allcondition")
$sql3 = "SELECT *FROM eq_inv WHERE eq_condition='Available/Unassigned'";
break;
case "new":
if ($condition == "allcondition")
$sql3 = "SELECT *FROM eq_inv WHERE eq_condition='Available/Unassigned' AND eq_state='new'";
break;
case "old":
if ($condition == "allcondition")
$sql3 = "SELECT *FROM eq_inv WHERE eq_condition='Available/Unassigned' AND eq_state='old'";
break;
case "Unknown state":
switch ($condition)
{
case "Available/Unassigned":
case "allcondition":
$sql3 = "SELECT *FROM eq_inv WHERE eq_condition='Available/Unassigned' AND eq_state='Unknown state'";
break;
}
}
You can try this:
<?php
$sql3="SELECT *FROM eq_inv WHERE eq_condition='Available/Unassigned'";
if(in_array($state, ['new', 'old', 'Unknown state']) && in_array($condition, ['allcondition', 'Available/Unassigned'])) {
$sql3 .=" AND eq_state='".$state."'";
}
$result3=mysqli_query($conn,$sql3);
$count=mysqli_num_rows($result3);
echo "<label style='color:red;'><strong>".$count."</strong></label>";
?>