- 论坛徽章:
- 0
|
代码如下:
<?php
$mysqli=new mysqli("localhost", "root", "root", "demo");
if(mysqli_connect_errno())
{
echo "数据库连接失败<br>",mysqli_connect_error();
exit();
}
$mysqli->query("set names gb2312");
$result=$mysqli->query("select name,email from contactInfo where departmentId='D01'");
echo 'D01部门的联系人姓名和邮箱:';
echo '<ol>';
while (list($name,$email)=$result->fetch_row());
{
echo '<li>'.$name.':'.$email.'</li>';
}
echo '</ol>';
$result->close();
$mysqli->close();
?>
在数据库中执行命令:
mysql> select name,email from contactInfo where departmentId='D01';
+--------+--------------------+
| name | email |
+--------+--------------------+
| 高某某 | gm@lampbrother.net |
| 陈某某 | cm@lampbrother.net |
+--------+--------------------+
2 rows in set (0.02 sec)
为什么页面显示不出来结果呢?如图:
|
|