Counting table results: A PHP switch case that uses a radio button value

前端 未结 3 763
没有蜡笔的小新
没有蜡笔的小新 2021-01-28 16:47

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

相关标签:
3条回答
  • 2021-01-28 17:00

    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.

    0 讨论(0)
  • 2021-01-28 17:15

    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.

    Update

    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;
    
            }
    }
    
    0 讨论(0)
  • 2021-01-28 17:19

    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>";
    ?>
    
    0 讨论(0)
提交回复
热议问题