这个不知道错哪了7,8行报错

WBOY
發布: 2016-06-13 10:14:32
原創
895 人瀏覽過

这个不知道哪里错了7,8行报错

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;
}
}
?>

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

PHP code
<?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;}}?><br><font color="#e78608">------解决方案--------------------</font><br>难道要<br>global $conn ;<br>$sql=mysql_query("select * from pro_type where belongs_id='".$belongs_id."'",$conn);<br><div class="clear">
                 
              
              
        
            </div>
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!