Php MYSQL将行提取到页面中
我正在从mysql获取数据到一个页面,我不确定我这样做是否合适。我在将值提取到页面的各个部分时遇到问题Php MYSQL将行提取到页面中,php,mysql,sql,Php,Mysql,Sql,我正在从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
<?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 -->
数据库;
上述产量
我想做以下几件事;
作者:法迪
echo'BY'$row['editor_name']。" " . $行['news_desc'];
回声“
”;
但它不起作用:(任何提示)如果要返回关联数组,可以尝试使用以下行:
...
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
...
你忘了在“BY”之后加一个点
echo 'BY' . $row['editor_name'] . ' ' . $row['news_desc'] . '<br />';
echo'BY'.$row['editor_name'..'..$row['news_desc'.]。
;
在“BY”之后缺少concat运算符。应为
echo 'BY' . $row['editor_name'] . " " . $row['news_desc'];
echo "<br />";
echo'BY'.$row['editor\u name'.''.'.$row['news\u desc'];
回声“
”;
或更整洁:
echo "BY {$row['editor_name']} {$row['news_desc']}<br/>";
echo“由{$row['editor_name']}{$row['news_desc']}
”;
搜索“$row['editor\u name']”下的“php mysql字符集utf-8”echo的可能重复项。$row['news\u desc'];echo“
”;
应为“echo”“BY”。$row['editor\u name']。$row['news\u desc'];echo”
;
echo "BY {$row['editor_name']} {$row['news_desc']}<br/>";