<?
include("includes/config.php");
//第 7,8 行报错
lei(0);
$ii=0;
function lei($belongs_id){
$sql=mysql_query("select * from pro_type where belongs_id='".$belongs_id."'",$conn);
while($rs_info=mysql_fetch_array($sql)){
//大类
if($belongs_id==0){
echo "大类";
}else{
echo "小类";
}
$ii=$ii+1;
lei($rs_info["id"]);
$ii=$ii-1;
}
}
?>

解决方案 »

  1.   

    数据库链接上了吗?输出SQL 到 mysql 执行一下看看有什么出错提示.
      

  2.   

    代码mysql_query()后再加一句 echo mysql_error();
    另外建议你不能光说哪一行出错,把错误信息贴全了别人才好判断
      

  3.   

    发现是变量作用域的问题。函数里的变量是局部变量,$conn要想使用全局变量,就得声明为global
      

  4.   

    显示下面的错误mysql_query(): supplied argument is not a valid MySQL-Link resource in <b>D:\phptest\APMServ5.2.6\www\htdocs\CManage\pro_type.phpmysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>D:\phptest\APMServ5.2.6\www\htdocs\CManage\pro_type.php
      

  5.   

    <?
    include("includes/config.php");
    //第 7,8 行报错
    lei(0);
    $ii=0;
    function lei($belongs_id){// 解决方法1, 不填$conn
    $sql=mysql_query("select * from pro_type where belongs_id='".$belongs_id."'");
    // 解决方法2, 以参数传递,或声明为全局
    // global $conn;
    // $sql=mysql_query("select * from pro_type where belongs_id='".$belongs_id."'", $conn);
    while($rs_info=mysql_fetch_array($sql)){
    //大类
    if($belongs_id==0){
    echo "大类";
    }else{
    echo "小类";
    }
    $ii=$ii+1;
    lei($rs_info["id"]);
    $ii=$ii-1;
    }
    }
    ?>
      

  6.   

    难道要
    global $conn ;
    $sql=mysql_query("select * from pro_type where belongs_id='".$belongs_id."'",$conn);
      

  7.   

    大家意见一致:$conn连接有问题!
    你先不传 $conn 试试。不行的话就要传递$conn了。
      

  8.   

    belongs_id什么类型的?int类型就不用加 ' 了。
    $conn是指mysql_connect()的值,不是mysql_select_db()的。
    查看影响行是否大于0:
    if (mysql_affected_rows() > 0){
       while(……
    }