2017-10-13 41 views
0

我试图从我的用户表中使用查询获取所有数据,并且我想通过回显显示它,并且这是我的代码,请帮助

<?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"; 
    } 
?> 

回答

1

你要(从$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"; 
    } 
    } 
} 
+1

试图删除print_r并遵循回声格式,它工作 非常感谢! – Ivann

+0

@Ivann很高兴帮助你:) :) –

+0

@AlivetoDie我可以通过电子邮件与你联系吗?或脸书,所以我可以问一些问题 – Ivann

-1
<?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