mysqli_result::fetch_array

mysqli_result::fetch_array -- mysqli_fetch_array — Fetch a result row as an associative(关联数组), a numeric array(索引数组), or both

面向对象风格
[mixed]mysqli_result::fetch_array ([ int $resulttype
= MYSQLI_BOTH ] )
过程化风格
[mixed]mysqli_fetch_array ( mysqli_result $result
[, int $resulttype
= MYSQLI_BOTH ] )

Returns an array that corresponds to the fetched row or **NULL
** if there are no more rows for the resultset represented by the result
parameter.

mysqli_fetch_array() is an extended version of the mysqli_fetch_row() function. In addition to storing the data in the numeric indices of the result array, the mysqli_fetch_array() function can also store the data in associative indices, using the field names of the result set as keys.

例子:

<?php
    $mysql = new mysqli('localhost','root','root','magicsuggest', 3306);
    $result = $mysql->query("select * from countries");
    while($row = $result->fetch_array(MYSQL_ASSOC)) {
?>
        <div class="checkbox">
            <label>
                <input type="checkbox" name="countries[]" value="<?php echo $row['idCountry']?>">
                <img src="<?php echo 'img/flags/png/' . strtolower($row['countryCode']) . '.png' ?>" />
                <?php echo $row['countryName'] .' ' . $row['population'] . ' ' . $row['capital'] . ' ' . $row['continentName']; ?>
            </label>
        </div>
<?php
    }
    $result->close();
    $mysql->close();
?>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,917评论 0 23
  • 人一旦步入青年时期,就知道什么是自己的天命了。在人生的这个阶段,一切都那么明朗,没有做不到的事情。期待完成他们一生...
    韩星子阅读 374评论 7 11
  • 题记:《神曲》系列的上一篇《夜寒中垂闭的小花》有幸于10月5日上了简书的首页,非常感谢简书的编辑和读者们的支持,我...
    猫隐阅读 1,953评论 0 2
  • 文/孤鸟差鱼 一场雨后 留下了一株没人采摘的喇叭花 你别难过 春天刚来 鱼和鸟还没相爱 那一汪海洋 在鱼群里 总能...
    孤鸟差鱼阅读 155评论 0 2