[英]MYSQL Fetching rows into page
我正在從mysql取數據到頁面,我不確定即時通訊的方式是否合適。 我在將值提取到頁面的各個部分時遇到麻煩。
<?php
// Connect to database server
mysql_connect("localhost", "xxx", "xxx") or die (mysql_error ());
// Select database
mysql_select_db("xxx") or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM news";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";
}
// Close the database connection
mysql_close();
?>
</div> <!-- content #end -->
數據庫;
以上收益;
我要執行以下操作; 作者:Fadi
echo 'BY' $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";
但它不起作用:(任何提示
您在“ BY”之后缺少concat運算符。 應該
echo 'BY' . $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";
或整理:
echo "BY {$row['editor_name']} {$row['news_desc']}<br/>";
如果要返回關聯數組,可以嘗試使用此行:
...
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
...
您在'BY'
之后忘記了一個點
echo 'BY' . $row['editor_name'] . ' ' . $row['news_desc'] . '<br />';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.