php输出mysqli查询出来的结果
时间:2021-07-01 10:21:17
帮助过:19人阅读
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[0];
- }
二:mysqli_fetch_assos();
查询结果:array([name]=>小王)
查询:
[php] view plain
copy
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[‘memberlist‘];
- }
三、mysqli_fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
[php] view plain
copy
- while ($row = mysqli_fetch_assoc($result)) {
- $memberlist = $row[‘memberlist‘];
- $memberlist = $row[0];
- }
四、fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
[php] view plain
copy
- $sql = "select * from user";
- $result = $conn->query($sql);
-
- if ($result)
- {
- if ($result->num_rows>0)
- {
- while ($rows = $result->fetch_array()) {
- print_r($rows);
- echo "<BR>rows[‘id‘]:".$rows[‘id‘];
- echo "<BR>rows[‘name‘]:".$rows[‘name‘];
- echo "<BR>rows[‘pwd‘]:".$rows[‘pwd‘];
- }
- }else{
- echo "<BR>查询结果为空!";
- }
- }else{
- echo "<BR>查询失败!";
- }
从上面可以看出不同的函数输出的格式也是不一样的,mysqli_fetch_row()返回的是以数字做索引的,mysqli_fetch_assos()是以关键字做索引的,而mysqli_fetch_array()和fetch_array()即使用数字也使用关键字做索引。
php输出mysqli查询出来的结果
标签:echo for mod cli tps class bar user https