doumeilmikv7099 2017-02-06 08:44
浏览 9
已采纳

在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.

  • 写回答

2条回答 默认 最新

  • dpb42021 2017-02-06 08:53
    关注

    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>';
    
    
       }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答