尽管使用" WHERE&#34 ;?为什么脚本会读取所有值?

时间:2015-02-25 20:35:57

标签: php database

我正在创建一个表,用于回显已回复的消息,而不回复消息。

我没有回复邮件的脚本运行良好,只有那些没有回复的邮件出现了。 但是我回复消息的另一个脚本回显了所有数据,两者都回复了,没有回复。

我的脚本在一个页面中,



        <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>
&#13;
&#13;
&#13;

我该如何改变?

1 个答案:

答案 0 :(得分:0)

通过更改第二个表中的一些代码来解决它

<?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>