我希望通过回声查看$ result的查询
问题描述:
我试图从我的用户表中使用查询获取所有数据,并且我想通过回显显示它,并且这是我的代码,请帮助
<?php
error_reporting(0);
require_once "helperfindercon.php";
$user_name = "joseph";
$user_pass = "joseph";
$mysql_qry = "select * from users";
$result = mysqli_query($conn, $mysql_qry);
if (mysqli_num_rows($result) > 0){
echo "$result";
}
else {
echo "error";
}
?>
答
你要(从$result
得到的所有记录,并告诉他们)申请while()
内if()
: -
if (mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
//print_r($row);// now check the array and echo accordingly.
foreach($row as $key=>$val){
echo $key.' :-'.$val."\n";
}
}
}
答
<?php
error_reporting(0);
require_once "helperfindercon.php";
$user_name = "joseph";
$user_pass = "joseph";
$mysql_qry = "select * from users";
$result = mysqli_query($conn, $mysql_qry);
if (mysqli_num_rows($result) > 0){
printt_r($result); // should use print_r as its type of array
}
else {
echo "error";
}
?>
+0
它只是显示一个空白 – Ivann
试图删除print_r并遵循回声格式,它工作 非常感谢! – Ivann
@Ivann很高兴帮助你:) :) –
@AlivetoDie我可以通过电子邮件与你联系吗?或脸书,所以我可以问一些问题 – Ivann