2017-10-13 39 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