我希望通过echo看到$ result的查询

时间:2017-10-13 11:57:22

标签: php mysqli

我正在尝试使用查询和我的用户表中的所有数据     想通过回声显示它,这是我的代码请帮助

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

2 个答案:

答案 0 :(得分:1)

您必须在while()内应用if()(以获取$result的所有记录并显示它们: -

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 :(得分:-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";
}  
?>