0
我有執行查詢,獲取結果,然後對這些結果執行操作的代碼。我想確保查詢不會返回空,否則while條件將失敗。檢查數組是否爲空,然後是條件
$ckey = $GLOBALS['ckey'];
$query3 = "SELECT * FROM uc_users WHERE id = $ckey;";
$result3 = mysqli_query($dbc, $query3);
if(!empty(mysqli_fetch_array($result3))
{
while($row3 = mysqli_fetch_array($result3))
{
$GLOBALS['cname'] = $row3['display_name'];
}
}
else{ echo "empty";}
這將返回 「致命錯誤:在寫上下文C不能使用函數返回值:」
$ckey = $GLOBALS['ckey'];
$query3 = "SELECT * FROM uc_users WHERE id = $ckey;";
$result3 = mysqli_query($dbc, $query3);
if(mysqli_num_rows(mysqli_fetch_array($result3)))
{
while($row3 = mysqli_fetch_array($result3))
{
$GLOBALS['cname'] = $row3['display_name'];
}
}
else{ echo "empty";}
返回「警告:mysqli_num_rows()預計參數1被mysqli_result,數組給定在C:」
嘗試'mysqli_num_rows($ result3)' –
臨屋它真的非常感謝你! – user2967081