while($rows = mysql_fetch_row($result)){
 echo "<option value=".$rows[1].">".$rows[0]."</option>";
 }
把里面的mysql_fetch_row变成mysql_fetch_array

解决方案 »

  1.   

    把里面的mysql_fetch_row变成mysql_fetch_array 还是不行如果不用函数我单独这么写就可以
    $result = mysql_query("select mingcheng,daima from mingcheng where leixing='类型名称' ",$conn); 
    echo “类型名称: <select name=mingcheng>";
    while($rows = mysql_fetch_row($result)){
    echo "<option value=".$rows[1].">".$rows[0]."</option>";
    }
    echo "</select>";
    这样就没事,放到函数中就不行了
      

  2.   

    奥才看到原来你还有一个Cliebiao函数呢。你那些链接数据库的代码函数里面引用不到的
      

  3.   

    global $conn;
    $result = mysql_query("select mingcheng,daima from mingcheng where leixing='".$mingcheng1."'",$conn);
      

  4.   


    <?php
    $conn = mysql_connect("localhost","root","root");//连接数据库,请填写你自己的用户名密码
    mysql_select_db("hxxx");//选择MYSQL数据库 
    mysql_query("set names utf-8");//设置为utf-8编码function Cliebiao($mingcheng1, $mingcheng2, $conn){
        $liebiao = "";
        $rows = "";
        $result = mysql_query("select mingcheng,daima from mingcheng where leixing='".$mingcheng1."'", $conn); 
        $liebiao .= "$mingcheng1: <select name=$mingcheng2>";
        while($rows = mysql_fetch_array($result)){
            $liebiao .= "<option value=".$rows[1].">".$rows[0]."</option>";
        }
        $liebao .= "</select>";
        return $liebiao;
    }
    $mingchenga="类型名称";
    $mingchengb="mingcheng";
    echo Cliebiao($mingchenga, $mingchengb, $conn);
    ?>1、请注意函数中尽量不要使用echo等输出类函数,这样会降低你的函数可重用性,你可以将函数中的内容return之后,将结果输出。
    2、6楼说的对,你的句柄是在外面生成的内部无法获得,请里明确的标明你的句柄再使用mysql_query函数。
      

  5.   

    你的程序没有问题,我试过了,是我的文字问题,我把$mingchenga="类型名称";条件去掉就可以,但显示出来是乱码,不知道怎么解决,请指教,谢谢!
      

  6.   


    非常感 谢你的指导,我按你这样写的还是不行
    非常感 谢你的指导,问题已解决把mysql_query("set names utf-8");换成mysql_query("set names utf8");就可以了
      

  7.   

    PHP函数内如何循环显示数据示例
    //导入数据连接
    <?php session_start();include("conn/conn.php");
    if($_GET[mail_id]==true){
    $query=mysql_query("update tb_mail_box set tb_mail_type=1 where tb_mail_id='$_GET[mail_id]'");
    }
    //数据库连接页面
    <?php
     $conn=mysql_connect("localhost","root","root"); //连接数据库服务器
     mysql_select_db("db_forum",$conn); //连接指定的数据库
     mysql_query("set names gb2312"); //对数据库中的编码格式进行转换,避免出现中文乱码的问题
    ?>
    //设置循环数据库表数据
    <?php  $query=mysql_query("select * from tb_mail_box where tb_mail_id='$_GET[mail_id]'"); //设置表sql语句
    $myrow=mysql_fetch_array($query);//循环数据
    ?>//codego.net/tags/4/1/
    //显示表字段信息
    <?php echo $myrow[tb_mail_subject];?>//显示数据表中Email信息
    <?php echo $myrow[tb_mail_content];?>//显示数据表中的某数量
    <?php  echo $myrow[tb_mail_sender];?>//显示数据表中邮件名称
    <?php  echo $myrow[tb_mail_date];?>//显示邮件时间