MySQL打印两次相同的记录

时间:2017-01-24 01:47:47

标签: php mysql

更新 经过进一步调查,文件似乎正在执行两次,因为在while循环外添加样本echo语句也会被打印两次。

我有一个php文件应该拉动我所有网站的用户并显示它们(格式化将在稍后出现),但由于某种原因,它似乎会遍历所有用户两次。 user_modify.php文件从另一个文件运行,其代码如下所示。

echo system("php templates/user_modify.php");

模板/ user_modify.php

<?php

    include('php/connect.php');

    $result = mysqli_query($conn, "SELECT `email`,`name`,`class`,`verified`,`created` FROM users");

    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo "Email: " . $row['email'] . "<br>";
            echo "Name: " . $row['name'] . "<br>";
            echo "Class: " . $row['class'] . "<br>";
            echo "Verified? " . ($row['verified'] === 0 ? "Yes" : "No") . "<br>";
            echo "Created on " . date("l, F jS, Y g:i a", strtotime($row['created'])) . "<br>";
        }
    }

?>

connect.php

<?php

    $conn = mysqli_connect("********************", "**********", "************", "**********");

?>

预期的内容

Email: email@example.com
Name: John Smith
Class: 2G
Verified? No
Created on Sunday, January 22nd, 2017 1:38 pm
Email: other_email@example.com
Name: Jimmy John
Class: 1B
Verified? No
Created on Monday, January 23rd, 2017 5:22 pm

实际输出

Email: email@example.com
Name: John Smith
Class: 2G
Verified? No
Created on Sunday, January 22nd, 2017 1:38 pm
Email: other_email@example.com
Name: Jimmy John
Class: 1B
Verified? No
Created on Monday, January 23rd, 2017 5:22 pm
Email: email@example.com
Name: John Smith
Class: 2G
Verified? No
Created on Sunday, January 22nd, 2017 1:38 pm
Email: other_email@example.com
Name: Jimmy John
Class: 1B
Verified? No
Created on Monday, January 23rd, 2017 5:22 pm

1 个答案:

答案 0 :(得分:0)

我遇到的问题是回显system函数的返回值。 system函数回显计算数据,并且附加echo语句第二次回显它。