【发布时间】:2015-04-25 20:47:07
【问题描述】:
我想从 MySql 表中检索数据。我正在使用 Xampp、phpMyAdmin 等...我一步一步按照本教程进行操作:https://www.youtube.com/watch?v=IHdd02IK2Jg
但我收到此错误:
注意:未定义变量:C:\XAMPP\htdocs\display_prsc.php 中第 29 行的记录
还有一个警告:
警告:mysql_fetch_assoc() 期望参数 1 是资源,在第 29 行的 C:\XAMPP\htdocs\display_prsc.php 中给出 null
当我运行它时它只显示列名。
<? php
//make connection
mysql_connect('localhost','root','');
//select_db
mysql_select_db('mynewdb');
$sql="SELECT * FROM new";
$records=mysql_query($sql);
?>
<html>
<head>
<title>Program Scores Table</title>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Year</th>
<th>Criteria</th>
<th>Score</th>
<tr>
<?php
while ($new=mysql_fetch_assoc($records)){
echo"<tr>";
echo"<td>".$new['py']."</td>";
echo"<td>".$new['pcrit']."</td>";
echo"<td>".$new['psco']."</td>";
echo"</tr>";
}
?>
</table>
</body>
</head>
</html>
【问题讨论】:
-
如果在你的教程中这个人使用
mysql_*,我强烈建议你停止本教程!并阅读:php.net/manual/en/book.pdo.php -
这段小代码有很多错误,写的很烂。
-
你的html是一团糟!
标签: php html mysql apache html-table