我正在尝试使用mysqli显示单行数据。 查询是
$getfield = mysqli_query($con,"select name from as_users where user_id=34");
if (mysqli_num_rows($getfield) > 0)
{
while($rowpwd = mysqli_fetch_array($getfield))
{
echo $rowpwd['name'];
}
}
如果我打印,那么我得到
echo '<pre>';
print_r(mysqli_fetch_array($getfield));
echo '</pre>';
Array
(
[0] => abc
[name] => abc
)
但是在while循环中获取名称不起作用。
非常感谢任何帮助。
答案 0 :(得分:1)
试试这个:
$getfield = mysqli_query($con,"select name from as_users where user_id=34");
if (mysqli_num_rows($getfield) > 0)
$whatYouWant = array();
{
while($rowpwd = mysqli_fetch_array($getfield))
{
//echo $rowpwd['name'];
$whatYouWant[] = $rowpwd['name'];
}
}
echo '<pre>';
print_r($whatYouWant);
echo '</pre>';
答案 1 :(得分:1)
试试这个:
$getfield = mysqli_query($con,"select name from as_users where user_id=34");
if (mysqli_num_rows($getfield) > 0)
{
$rowpwd = mysqli_fetch_array($getfield)['name'];
echo $rowpwd;
}
OR
$getfield = mysqli_query($con,"select name from as_users where user_id=34");
if (mysqli_num_rows($getfield) > 0)
{
$rowpwd = mysqli_fetch_array($getfield);
echo $rowpwd['name'];
}
答案 2 :(得分:0)
变化:
mysqli_fetch_array
收件人:如果你想要行的键
mysqli_fetch_assoc
收件人:如果你想要行的索引
mysqli_fetch_row