MySQL语句不会在while中回显变量

时间:2012-02-02 16:37:23

标签: php mysql

所以我有以下内容:

$query = "SELECT id,account,status FROM service WHERE status = 'Unpaid'";
        $result = mysql_query($query);  

    while($row = mysql_fetch_row($result)){

                $id = $row[0];
                $dateEntered = $row[1];
                $type = $row[2];
                $account = $row[3];
                $dateCompleted = $row[4];
                $notes = $row[5];
                $status = $row[6];

            echo $account;
          // mailStatusUpdate($account, $status, $dateEntered);

        }   

echo mysql_error();

在phpmyadmin中查询进程正常。当我回显未付状态记录的$帐户时,它不会回显。有什么问题? PHPmyadmin处理一切正常并向我显示记录?

2 个答案:

答案 0 :(得分:4)

您只从查询中检索三列。

$ account应设为$account = $row[1];

$ status应设置为$status = $row[2];

答案 1 :(得分:0)

您只选择3个字段(id(0),account(1),status(2)) 所以$ account = $ row [1]会回复账号;没有$ row [3]。 如果要获取所有列,请使用SELECT * FROM service WHERE .....

也可以获取值,使用键

    $query = "SELECT * FROM service WHERE status = 'Unpaid'";
    $result = mysql_query($query);  

       while($row = mysql_fetch_assoc($result)){

            $id = $row['id'];
            $dateEntered = $row['dateEntered'];
            $type = $row['type'];
            $account = $row['account'];
            $dateCompleted = $row['dateCompleted'];
            $notes = $row['notes'];
            $status = $row['status'];

        echo $account;
      // mailStatusUpdate($account, $status, $dateEntered);

    }