duanjiancong4860 2015-02-25 20:35
浏览 29
已采纳

尽管使用“WHERE”,为什么脚本会读取所有值?

I am creating a table that echo out replied messages and not replied messages.

My script for not replied messages worked well,only those not replied appeared. But my other script for replied messages echo all data, both replied and not replied.

my script in one page,

        <div class="container">
            <div class="row">
                <?php
                require_once 'dbfunction.php';
                $con = getDbConnect();
                

                if (!mysqli_connect_errno($con)) {
                    $sqlQueryStr = "SELECT * FROM feedback  WHERE status = 0";

                    $result = mysqli_query($con, $sqlQueryStr);

                    while ($row = mysqli_fetch_array($result)) { // fetch the record
                        $feedback[$row['record']] = $row;
                    }

                    mysqli_close($con);
                } else {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                ?>

                <div class="container">
                    <h2>Customer Feedback - await for reply</h2>     
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Firstname</th>
                                <th>Lastname</th>
                                <th>Email</th>
                                <th>Relpy</th>
                            </tr>
                        </thead>
                        <?php
                        foreach ($feedback as $id => $info) {
                            echo '<tbody>';
                            echo '<tr>';
                            echo '<td>' . $info['name'] . '</td>';
                            echo '<td>' . $info['email'] . '</td>';
                            echo '<td>' . $info['message'] . '</td>';
                            echo '<td><button class="btn btn-info">' . 'Reply' . '</button></td>';
                            echo '</tr>';
                            echo '</tbody>';
                        }
                        ?>
                    </table>
                </div>

            </div>
        </div>
        
        <div class="container">
            <div class="row">
                <?php
                require_once 'dbfunction.php';
                $con = getDbConnect();
                

                if (!mysqli_connect_errno($con)) {
                    $sqlQueryStr = "SELECT * FROM feedback  WHERE status != 0";

                    $result = mysqli_query($con, $sqlQueryStr);

                    while ($row = mysqli_fetch_array($result)) { // fetch the record
                        $feedback[$row['record']] = $row;
                    }

                    mysqli_close($con);
                } else {
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                ?>

                <div class="container">
                    <h2>Customer Feedback - Replied</h2>     
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Firstname</th>
                                <th>Lastname</th>
                                <th>Email</th>
                                <th>Relpy</th>
                            </tr>
                        </thead>
                        <?php
                        foreach ($feedback as $id => $info) {
                            echo '<tbody>';
                            echo '<tr>';
                            echo '<td>' . $info['name'] . '</td>';
                            echo '<td>' . $info['email'] . '</td>';
                            echo '<td>' . $info['message'] . '</td>';
                            echo '<td>' . 'Replied' . '</td>';
                            echo '</tr>';
                            echo '</tbody>';
                        }
                        ?>
                    </table>
                </div>

            </div>
        </div>

How can i change it?

</div>
  • 写回答

1条回答 默认 最新

  • dtz55359 2015-02-25 20:52
    关注

    Solve it by changing some of the codes in the second table

    <?php
                    require_once 'dbfunction.php';
                    $con = getDbConnect();
                    
    
                    if (!mysqli_connect_errno($con)) {
                        $sqlQueryStr = "SELECT * FROM feedback  WHERE status != 0";
    
                        $result2 = mysqli_query($con, $sqlQueryStr);
    
                        while ($row2 = mysqli_fetch_array($result2)) { // fetch the record
                            $feedback2[$row2['record']] = $row2;
                        }
    
                        mysqli_close($con);
                    } else {
                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
                    }
                    ?>
    
                    <div class="container">
                        <h2>Customer Feedback - Replied</h2>     
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Firstname</th>
                                    <th>Lastname</th>
                                    <th>Email</th>
                                    <th>Relpy</th>
                                </tr>
                            </thead>
                            <?php
                            foreach ($feedback2 as $id2 => $info2) {
                                echo '<tbody>';
                                echo '<tr>';
                                echo '<td>' . $info2['name'] . '</td>';
                                echo '<td>' . $info2['email'] . '</td>';
                                echo '<td>' . $info2['message'] . '</td>';
                                echo '<td>' . 'Replied' . '</td>';
                                echo '</tr>';
                                echo '</tbody>';
                            }
                            ?>
                        </table>
                    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制