
$row=mysql_fetch_array($result); 测试网页上面这句老报错,谁帮帮啊这菜鸟啊,谢谢了
<?phpheader("content-type:text/html;charset=utf-8");//数据库配置信息$db_host="localhost";$db...
<?php
header("content-type:text/html;charset=utf-8");
//数据库配置信息
$db_host="localhost";
$db_user="root";
$db_pwd="root";
$db_name="saixinjituan";
$db_prefix="007_";
//(1)连接MySQL数据库
$link =@mysql_connect($db_host,$db_user,$db_pwd);
if(!$link)
{
exit("<li>连接MySQL数据库失败!</li>");
}
//(2)选择当前数据库
if(!mysql_select_db($db_name,$link))
{
exit("<li>连接数据库{$db_name}失败!</li>");
}
//(3)设置返回数据库的字符集
mysql_query("set names utf8");
//查询数据
$sql="select * from{$db_prefix}news order by id desc ";
$result = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
td,th{ padding:5px; color:#444; font-size:14px; border:1px solid #ccc}
</style>
</head>
<body>
<table width="800" border="1" style="border-collapse:collapse" align="center">
<tr>
<th scope="col">编号</th>
<th scope="col">标题</th>
<th scope="col">作者</th>
<th scope="col">来源</th>
<th scope="col">排序</th>
<th scope="col">点击率</th>
<th scope="col">发布时间</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
print_r($row)
?>
<tr>
<td><?php echo $row[0]?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php }?>
</table>
</body>
</html> 展开
header("content-type:text/html;charset=utf-8");
//数据库配置信息
$db_host="localhost";
$db_user="root";
$db_pwd="root";
$db_name="saixinjituan";
$db_prefix="007_";
//(1)连接MySQL数据库
$link =@mysql_connect($db_host,$db_user,$db_pwd);
if(!$link)
{
exit("<li>连接MySQL数据库失败!</li>");
}
//(2)选择当前数据库
if(!mysql_select_db($db_name,$link))
{
exit("<li>连接数据库{$db_name}失败!</li>");
}
//(3)设置返回数据库的字符集
mysql_query("set names utf8");
//查询数据
$sql="select * from{$db_prefix}news order by id desc ";
$result = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
td,th{ padding:5px; color:#444; font-size:14px; border:1px solid #ccc}
</style>
</head>
<body>
<table width="800" border="1" style="border-collapse:collapse" align="center">
<tr>
<th scope="col">编号</th>
<th scope="col">标题</th>
<th scope="col">作者</th>
<th scope="col">来源</th>
<th scope="col">排序</th>
<th scope="col">点击率</th>
<th scope="col">发布时间</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
print_r($row)
?>
<tr>
<td><?php echo $row[0]?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php }?>
</table>
</body>
</html> 展开
1个回答
展开全部
var_dump() 一下你的 $result, 看看是不是取到了数据。 这里我不知道有没有关系, 改成 $row = mysql_fetch_array($result, MYSQL_NUM) 。 不行的话再var_dump()一下 mysql_fetch_array($result), 看看哪个环节有问题。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询