dongshao2967 2014-08-01 22:57
浏览 171

mysqli_fetch_array返回空结果[关闭]

I want to create a select list according to the mySQL database, but I get empty results when using mysqli_fetch_array. The options number is correct, but all empty.

Here's the code:

$rows = mysqli_num_rows($result);
$self = $_SERVER['PHP_SELF'];
    <div id='editUser'>
        <span class='ACtitle'>Edit Users</span>
        <div id='addField'>
            <form action="<?php $self ?>" method="post">
                <select name="target" size="1">
                    <option value='none'>Select user you wish to edit.</option>
<?php
    for($ii = 0; $ii <= $rows; $ii++)
    {
        $sqlSta3 = "select name from 'users'";
        $result2 = mysqli_query($database, $sqlSta3);

        $nameArray = mysqli_fetch_array($result2);

        print_r($nameArray);

        $tableName = $nameArray['name'];
        print "<option value='$tableName'> $tableName </option>";

    }
?>

                </select>
                <input type="text" name="updateName"
            </form>
        </div>
    </div>
  • 写回答

1条回答 默认 最新

  • dtnnpt11795 2014-08-01 23:22
    关注

    You need to replace the mysql_fetch_array with mysql_fetch_assoc to use your method. mysql_fetch_array returns array like this [0] => "data",[1] => "data" mysql_fetch_assoc returns array with the name of the cells in your table ['username'] => 'data',['fname'] => "data";

    Here is the fixed code:

    $rows = mysqli_num_rows($result);
    $self = $_SERVER['PHP_SELF'];
        <div id='editUser'>
            <span class='ACtitle'>Edit Users</span>
            <div id='addField'>
                <form action="<?php $self ?>" method="post">
                    <select name="target" size="1">
                        <option value='none'>Select user you wish to edit.</option>
    <?php
        for($ii = 0; $ii <= $rows; $ii++)
        {
            $sqlSta3 = "SELECT name From users ";
            $result2 = mysqli_query($database, $sqlSta3);
    
            $nameArray = mysqli_fetch_assoc($result2);
    
            print_r($nameArray);
    
            $tableName = $nameArray['name'];
            print "<option value='$tableName'> $tableName </option>";
    
        }
    ?>
    
                    </select>
                    <input type="text" name="updateName"
                </form>
            </div>
        </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码