我声明了一个过程User_Name
function User_Name($Id){//显示用户名
$rs=mysql_fetch_object(mysql_query("select * from name_User where tId = '$Id'"));
echo $rs->tName;
}
我用
     User_Name(1);
可以正常的显示出用户名来但是我用
User_Name(ZT_UserId($Id_ZT));
却不能正常的显示出用户名来
只显示一个用户的Id:1来
而过程ZT_UserId($Id_ZT)就是显示一个用户的Id
我用下面的软件函数也不行哦.
User_Name(intval(ZT_UserId($Id_ZT)));
要怎么要才能让User_Name(ZT_UserId($Id_ZT));可以正常的显示出用户名呢?

解决方案 »

  1.   


    ZT_UserId($Id)过程:
    function ZT_UserId($Id){//显示主题作者的Id
    $rs=mysql_fetch_object(mysql_query("select tUserId from name_ZTLB where tId ='$Id'"));
    echo $rs->tUserId;
    }
      

  2.   

    你的ZT_UserId()函数能执行吗,看起来好像函数体中没有声明数据库连接资源为全局变量啊,如果在调用函数时已经连接数据库了(假设连接资源保存在$conn变量中),语句改成下面这样试试:
    function ZT_UserId($Id){//显示主题作者的Id
    global $conn;
    $rs=mysql_fetch_object(mysql_query("select tUserId from name_ZTLB where tId ='$Id'",$conn));
    echo $rs->tUserId;
    }
      

  3.   


    ZT_UserId()可以正常执行的,<? 
       echo "[";
    ZT_UserId($Id_ZT);
       echo "]"; 可以正常的显示出 [1] 来
    ?>
      

  4.   

    唉,真是无奈啊,
    我改成了这样function ZT_User_Name($Id){//显示主题作者的名字
    $rs=mysql_fetch_object(mysql_query("select * from name_ZTLB where tId ='$Id'"));
    $rs2=mysql_fetch_object(mysql_query("select * from name_User where tId ='$rs->tUserId'"));
    //echo $rs2->tUserId;
    echo $rs2->tName;
    用这个ZT_User_Name($Id_ZT)调用
      

  5.   

    你在开玩笑吧?
    在初中课程中你就学过:函数是取得自变量的应变量的值在你写的函数中都没有返回值的吗?
    至少要
    function ZT_UserId($Id){//显示主题作者的Id
      $rs=mysql_fetch_object(mysql_query("select tUserId from name_ZTLB where tId ='$Id'"));
      return $rs->tUserId;
    }
      

  6.   


    谢谢了,实验成功了,我的学校没教过php,就算是VB也只是讲了一点点皮毛.我用下面的实验也没有成功,以前学VB时的思路就是这样的.
    ZT_UserId(1,$UserName);
    print $UserName;function ZT_UserId($Id,$tId){//显示主题作者的Id
      $rs=mysql_fetch_object(mysql_query("select tUserId from name_ZTLB where tId ='$Id'"));
      $tId=$rs->tUserId;
    }
      

  7.   

    一般写函数都不要再函数里 echo  而是返回一个结果 然后再 echo 或者print_r 之类的.