美文网首页
mysqli_result::fetch_array

mysqli_result::fetch_array

作者: JasonQiao | 来源:发表于2016-08-02 15:00 被阅读99次

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();
?>

相关文章

网友评论

      本文标题:mysqli_result::fetch_array

      本文链接:https://www.haomeiwen.com/subject/ilwfsttx.html