duanjiancong4860
duanjiancong4860
2015-02-25 20:35

尽管使用“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 dtz55359 6年前

    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>
    
    点赞 评论 复制链接分享