gpt4 book ai didi

php - MYSQL 将行提取到页面中

转载 作者:行者123 更新时间:2023-11-29 14:31:22 27 4
gpt4 key购买 nike

我正在从 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 -->

数据库; db

上述 yield ;

news

我想做以下事情;作者:法迪

echo 'BY' $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";

但它不起作用:(任何提示

最佳答案

“BY”后面缺少连接运算符。应该是

echo 'BY' . $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";

或者更整洁:

echo "BY {$row['editor_name']} {$row['news_desc']}<br/>";

关于php - MYSQL 将行提取到页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9967950/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com