2017-07-22 77 views
-1

我在大約mysql_fetch_assoc代碼警告(),但我認爲代碼是罰款警告:mysqli_fetch_assoc()預計參數1被mysqli_result,布爾

<?php 
     $con = mysqli_connect("localhost","root","","profiles"); 
     $q = mysqli_query($con,"SELECT * FROM users"); 
     while($row = mysqli_fetch_assoc($q)){ 
      echo $row['username']; 
      if($row['image'] == ""){ 
       echo "<img width='100' height='100' src='pictures/default.jpg' alt='Default Profile Pic'>"; 
      } else { 
       echo "<img width='100' height='100' src='pictures/".$row['image']."' alt='Profile Pic'>"; 
      } 
      echo "<br>"; 
     } 
    ?> 
+0

您的查詢失敗。檢查'profiles'數據庫中是否真的存在表'users'。 –

+1

問題主體說你正在使用'mysql_fetch_assoc()',是一個錯字? – chris85

回答

0

這意味着你的查詢失敗。這裏的智能移動將檢查您的查詢是否返回false,如下所示:

if(!$q){ 
    die("Error in query:". mysqli_error($con)); 
} 
0

首先您必須檢查錯誤。

$con = mysqli_connect("localhost","root","","profiles"); 
$q = mysqli_query($con,"SELECT * FROM users"); 

if (false === $q) { 
    echo mysqli_error(); 
}else{ 

    while($row = mysqli_fetch_assoc($q)){ 
     echo $row['username']; 
     if($row['image'] == ""){ 
      echo "<img width='100' height='100' src='pictures/default.jpg' alt='Default Profile Pic'>"; 
     } else { 
      echo "<img width='100' height='100' src='pictures/".$row['image']."' alt='Profile Pic'>"; 
     } 
     echo "<br>"; 
    } 
} 
相關問題