-1

我正在尝试使用 PHP mysql_fetch_assoc 函数并将我的表记录返回到 html 表中。我现在表中只有一条记录,当我运行这个 PHP 脚本时,如果我这样做,它会返回单个记录的值......

print_r(mysql_fetch_assoc($QueryResult));

最终返回...

Array ( [field_date] => 2013-10-03 [field_time] => 00:00:17 [name] => Dave [message] => This is a message. [switch] => Y )

但以下内容不会将值放入 html 表格行中,我需要帮助。

$SQLstring = "SELECT * FROM `table` WHERE switch = 'Y'";

    // Run query and place in variable
    $QueryResult = mysql_query($SQLstring, $DBConnect);

    print_r(mysql_fetch_assoc($QueryResult));

    // Set the fetch command to the query recordset
    $Row = mysql_fetch_assoc($QueryResult);

    // Return records into a formatted table
    echo    "<table width='100%' border='1'>\n";
    echo    "<tr><th>Date</th><th>Time</th><th>Name</th>
        <th>Message</th><th>Switch</th></tr>\n";
    while ($Row = $result -> mysql_fetch_row($QueryResult)) {
        echo    "<tr><td>{$Row['field_date']}</td>";
        echo    "<td>{$Row['field_time']}</td>";
        echo    "<td>{$Row['name']}</td>";
        echo    "<td>{$Row['message']}</td>";
        echo    "<td>{$Row['switch']}</td></tr>";
    }
    echo "</table>\n";
4

2 回答 2

1

尝试这个

$SQLstring = "SELECT * FROM `table` WHERE switch = 'Y'";

    // Run query and place in variable
    $QueryResult = mysql_query($SQLstring, $DBConnect);



    // Return records into a formatted table
    echo    "<table width='100%' border='1'>\n";
    echo    "<tr><th>Date</th><th>Time</th><th>Name</th>
        <th>Message</th><th>Switch</th></tr>\n";
    while ($Row = mysql_fetch_assoc($QueryResult)) {
        echo    "<tr><td>{$Row['field_date']}</td>";
        echo    "<td>{$Row['field_time']}</td>";
        echo    "<td>{$Row['name']}</td>";
        echo    "<td>{$Row['message']}</td>";
        echo    "<td>{$Row['switch']}</td></tr>";
    }
    echo "</table>\n";
于 2013-10-04T04:18:45.537 回答
0
while( $Row = mysql_fetch_array($QueryResult) ){
          print_r($Row);
          echo "<br />";
}
于 2013-10-04T04:18:38.457 回答