我想使用PHP mysql_fetch_assoc函數並將我的表記錄返回到html表中。我只有一個記錄表中,現在,當我運行這最終返回這個PHP腳本返回,如果我做的唯一記錄的值...不能讓mysql_fetch_assoc()工作,但可以打印關聯數組 - 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";
僅供參考MySQL擴展已被棄用,不再開發或支持。請切換到MySQLi或PDO擴展 – Phil
謝謝,絕對值得注意。 – codingManiac