Home > Backend Development > PHP Tutorial > php输出mysqli查询出来的结果

php输出mysqli查询出来的结果

WBOY
Release: 2016-06-23 13:33:50
Original
1323 people have browsed it

php连接mysql我有文章已经写过了,这篇文章主要是介绍从mysql中查询出结果之后怎么输出的问题。
一:mysqli_fetch_row();
查询结果:array([0]=>小王)
查询:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row[0];
}//end while()

二:mysqli_fetch_assos();
查询结果:array([name]=>小王)
查询:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row['memberlist'];
}//end while()

三、mysqli_fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:
while ($row = mysqli_fetch_assoc($result)) {
$memberlist = $row['memberlist'];
$memberlist = $row[0];
}//end while()

四、fetch_array();
查询结果:array([0]=>小王 [name]=>小王)
查询:` sql=“select?fromuser”; result = conn?>query( sql);

if (result)  
{  
    if (result->num_rows>0)
{
while ( rows= result->fetch_array()) {
print_r( rows);echo“rows[‘id′]:”. rows[‘id’];
echo “
rows[‘name’]:”. rows[‘name′];echo“rows[‘pwd′]:”. rows[‘pwd’];
}//end while()
}else{
echo “
查询结果为空!”;
}//end if()
}else{
echo “
查询失败!”;
}//end if() `

从上面可以看出不同的函数输出的格式也是不一样的,mysqli_fetch_row()返回的是以数字做索引的,mysqli_fetch_assos()是以关键字做索引的,而mysqli_fetch_array()和fetch_array()即使用数字也使用关键字做索引。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template