Rumah  >  Artikel  >  pembangunan bahagian belakang  >  入门事例php mysql中读取表中数据失败,求大侠指教

入门事例php mysql中读取表中数据失败,求大侠指教

WBOY
WBOYasal
2016-06-13 12:58:10749semak imbas

入门例子php mysql中读取表中数据失败,求大侠指教
1.问题:用php读mysql中的一张表,怎么也读不出来,页面有时空白,有时有php中的一小节代码,苦调了一天了,求指导!感激不尽!!
2.mysql中,数据库:test;表名:apple;(字段:firstname,lastname)
3.index.php(试过连接数据库成功)
代码:

<br />
<html><br />
<head><br />
<title>php分页示例</title><br />
<meta http-equiv="content-Type" content="text/html; charset=utf-8"><br />
</head><br />
<br />
<body><br />
<?php<br />
$dbh = @mysql_connect("localhost","root","");<br />
if(!$dbh){die("error");}<br />
@mysql_select_db("test", $dbh);<br />
$sql = "SELECT * FROM apple";<br />
?><br />
<?<br />
$rs = mysql_query($sql, $dbh);<br />
while($row = mysql_fetch_array($rs)) <br />
echo $row[id];<br />
echo $row[name];<br />
echo '<br/>';<br />
?><br />
<?<br />
@mysql_close($dbh);<br />
?> <br />
<br />
<br />
</body><br />
</html> <br />

请各大侠帮帮忙,叩谢!!
------解决方案--------------------

本帖最后由 PhpNewnew 于 2012-05-27 17:51:30 编辑 日志错误只是有个默认图标不存在的提示,没有关系的.

仔细看了下代码
while($row = mysql_fetch_array($rs)) 
echo $row[id];
echo $row[name];
echo '
';
?>

这里添加上括号

while($row = mysql_fetch_array($rs)) {
echo $row[id];
echo $row[name];
echo '
';
}
?>

保存后刷新 看看


另外你不说数据库内是
(字段:firstname,lastname)

怎么跑出个 $row['id']? $row['name']?出来了
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn