php从mysql中取数据显示出错

鲁大师
  • 3
新手上路,请多包涵
<?php
header("content-type:text/html;charset=utf-8");
$conn=mysql_connect('localhost','root','root') or die('数据库连接失败!');
mysql_select_db('student');
mysql_query('set names utf8');
$rs=mysql_query("select * from stu_grade");

echo "<table width='900' border='1' bordercolor='blue'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>姓名</th>";
echo "<th>分数</th>";
echo "</tr>";

while ($row=mysql_fetch_row($rs)) {
    echo "<tr>";
    echo "<td>{$row[0]}<td>";    
    echo "<td>{$row[1]}<td>";
    echo "<td>{$row[2]}<td>";
    echo "</tr>";
}
echo "</table>";

?>

图片描述

回复
阅读 999
1 个回答
Tuesday
  • 138
✓ 已被采纳

echo "<tr>";
echo "<td>{$row[0]}</td>";
echo "<td>{$row[1]}</td>";
echo "<td>{$row[2]}</td>";
echo "</tr>";

改成这样.

建议直接学习mysqli或者pdo,

宣传栏