我是php菜鸟求大神指点 下面的程序出现mysql_fetch_array() expects parameter 1 to be resource错误
<?phpob_start();session_start();require_once("inc/conn1.inc");$result=mysql_query("SE...
<?php
ob_start();
session_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while(mysql_fetch_array($result))
{
$rowarray[1]=$row['username'];
$rowarray[2]=$row['password'];
$rowarray[3]=$row['telphone'];
$rowarray[4]=$row['userquan'];
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$rowarray[1] ;
echo "</td>";
echo "<td>" ;
echo "密码:" .$rowarray[2] ;
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$rowarray[3] ;
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$rowarray[4] ;
echo "</td>";
echo "</table>";
}
?> 展开
ob_start();
session_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while(mysql_fetch_array($result))
{
$rowarray[1]=$row['username'];
$rowarray[2]=$row['password'];
$rowarray[3]=$row['telphone'];
$rowarray[4]=$row['userquan'];
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$rowarray[1] ;
echo "</td>";
echo "<td>" ;
echo "密码:" .$rowarray[2] ;
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$rowarray[3] ;
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$rowarray[4] ;
echo "</td>";
echo "</table>";
}
?> 展开
3个回答
展开全部
写法错了:
while(mysql_fetch_array($result))
你没有把里面的mysql_fetch_array保存为变量
<?php
ob_start();
session_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while($rowarray=mysql_fetch_array($result))
{
if(!$rowarray)//如果记录集为空
{
echo '对不起,没有记录';
break;
}
$rowarray[1]=$row['username'];
$rowarray[2]=$row['password'];
$rowarray[3]=$row['telphone'];
$rowarray[4]=$row['userquan'];
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$rowarray[1] ;
echo "</td>";
echo "<td>" ;
echo "密码:" .$rowarray[2] ;
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$rowarray[3] ;
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$rowarray[4] ;
echo "</td>";
echo "</table>";
}
?>
while(mysql_fetch_array($result))
你没有把里面的mysql_fetch_array保存为变量
<?php
ob_start();
session_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while($rowarray=mysql_fetch_array($result))
{
if(!$rowarray)//如果记录集为空
{
echo '对不起,没有记录';
break;
}
$rowarray[1]=$row['username'];
$rowarray[2]=$row['password'];
$rowarray[3]=$row['telphone'];
$rowarray[4]=$row['userquan'];
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$rowarray[1] ;
echo "</td>";
echo "<td>" ;
echo "密码:" .$rowarray[2] ;
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$rowarray[3] ;
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$rowarray[4] ;
echo "</td>";
echo "</table>";
}
?>
追问
我已经给mysql_fetch_array($result)赋值了
追答
写法错了:
while(mysql_fetch_array($result))
你没有把里面的mysql_fetch_array保存为变量
";
echo "" ;
echo "您的信息如下:" ;
echo"";
echo "" ;
echo "用户名:" .$rowarray['username'] ;
echo "";
echo "" ;
echo "密码:" .$row['password'];
echo "";
echo "" ;
echo "手机号码:" $row['telphone'];
echo "";
echo "" ;
echo "用户类型:" .$row['userquan'];
echo "";
echo "";
}
?>
我记得:
$rowarray[1]=$row['username'];
$rowarray[2]=$row['password'];
$rowarray[3]=$row['telphone'];
$rowarray[4]=$row['userquan'];
这么写不合法,,,
展开全部
session_start();要放到最前面
<?php
session_start();
ob_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while($row=mysql_fetch_array($result))
{
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$row['username'];
echo "</td>";
echo "<td>" ;
echo "密码:" .$row['password'];
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$row['telphone'];
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$row['userquan'];
echo "</td>";
echo "</table>";
}
?>
<?php
session_start();
ob_start();
require_once("inc/conn1.inc");
$result = mysql_query("SELECT * FROM users");
while($row=mysql_fetch_array($result))
{
echo "<table>";
echo "<td>" ;
echo "您的信息如下:" ;
echo"</td>";
echo "<td>" ;
echo "用户名:" .$row['username'];
echo "</td>";
echo "<td>" ;
echo "密码:" .$row['password'];
echo "</td>";
echo "<td>" ;
echo "手机号码:" .$row['telphone'];
echo "</td>";
echo "<td>" ;
echo "用户类型:" .$row['userquan'];
echo "</td>";
echo "</table>";
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
补充下一楼的内容,ob_start(),session_start(),header()这两个函数在使用前都不向有任何输出,但排位没有先后顺序,即哪个在前都无所谓
回答下楼主的问题,关键是这里while(mysql_fetch_array($result)),没有给抓出来的记录集赋值,试着改成这样看看while($row=mysql_fetch_array($result))
回答下楼主的问题,关键是这里while(mysql_fetch_array($result)),没有给抓出来的记录集赋值,试着改成这样看看while($row=mysql_fetch_array($result))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询