在Mysql中按字段筛选行

I want if staff go to application page to view the list of application from student. it will only view the status of apply_status = 'PENDING' . status that already approved before will not view in the page. ................................................................................

This is my code if only the apply_status = 'PENDING' will only view in the page. ... I add the if else statement... but is not working. if there is several apply_status = approved. It will not showed the pending one. But if there is no apply_status = aprroved. It will view all the application.

<?php
    include("connection.php");
    $sql="SELECT * FROM application";
    $record = mysqli_query($con, $sql) or die ("error".mysqli_error($con));
    $apply = mysqli_fetch_assoc($record);

    $status1 = $apply["apply_status"];

    if ($status1 == "APPROVED") {
        echo "<br>";
        echo "No application from student yet.<br>";
        echo "<br>";
    }

    else {

    echo "<table border='1'><tr>

    <td><strong>Student ID</strong></td>
    <td><strong>Student Name</strong></td>
    <td><strong>Kelompok</strong></td>
    <td><strong>Block</strong></td>
    <td><strong>Level</strong></td>
    <td><strong>House</strong></td>
    <td><strong>Status</strong></td>


    </tr>";
    $i=0;
    while ($ww=mysqli_fetch_array($query))
    {
        if ($i%2==0)
            $class="evenRow";
        else
            $class="oddRow";

        $id=$ww[0];
        $studentid=$ww[1];
        $name=$ww[2];
        $kelompok=$ww[8];
        $block=$ww[9];
        $level=$ww[10];
        $house=$ww[11];
        $status=$ww[14];



    echo '<tr>
        <input type="hidden" name="applyid['.$i.']" value="'.$id.'"/>
        <td>'.$studentid.'</td>
        <td>'.$name.'</td>
        <td>'.$kelompok.'</td>
        <td>'.$block.'</a></td>
        <td>'.$level.'</td>
        <td>'.$house.'</td>
        <td>
            <input type="checkbox" name="status['.$i.']" value="approved" checked> APPROVED <br>
        </td>
        </tr>'; 
    $i++;
    }

    echo '</table>';

    }

i think the error is at the if else statement but i dont know how to differentiate the apply_status = approved and apply_status = pending.

Try this, Remember,

$status1 = $apply["apply_status"];

should be part of loop, there are may rows that has it.

    <?php
    include("connection.php");
    $sql="SELECT * FROM application";
    $record = mysqli_query($con, $sql) or die ("error".mysqli_error($con));
    $i=0;
    $number_of_rows = mysql_num_rows($record);

     if ($number_of_rows == 0) {
            echo "<br>";
            echo "No application from student yet.<br>";
            echo "<br>";
     } else {
      while ($ww=mysqli_fetch_array($record))
     {

    echo "<table border='1'><tr>

    <td><strong>Student ID</strong></td>
    <td><strong>Student Name</strong></td>
    <td><strong>Kelompok</strong></td>
    <td><strong>Block</strong></td>
    <td><strong>Level</strong></td>
    <td><strong>House</strong></td>
    <td><strong>Status</strong></td>


    </tr>";


        if ($i%2==0)
            $class="evenRow";
        else
            $class="oddRow";

        $id=$ww[0];
        $studentid=$ww[1];
        $name=$ww[2];
        $kelompok=$ww[8];
        $block=$ww[9];
        $level=$ww[10];
        $house=$ww[11];
        $status=$ww[14];



    echo '<tr>
        <input type="hidden" name="applyid['.$i.']" value="'.$id.'"/>
        <td>'.$studentid.'</td>
        <td>'.$name.'</td>
        <td>'.$kelompok.'</td>
        <td>'.$block.'</a></td>
        <td>'.$level.'</td>
        <td>'.$house.'</td>
        <td>
            <input type="checkbox" name="status['.$i.']" value="approved" checked> APPROVED <br>
        </td>
        </tr>'; 
    $i++;
    }

    echo '</table>';


   }

Im not found "staff" condition in your code,,

include("connection.php");

$sql="SELECT * FROM application";

if($staff){
$sql = $sql. " WHERE apply_status = 'PENDING'";
}else{
$sql = $sql. " WHERE apply_status = 'APPROVED'";
}