我想用php从mysql数据库中获取我的JSON数据。但输出说:
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,
这是我的PHP代码,请帮我修复此错误。谢谢。
<?php
header("Access-Control-Allow-Origin: *");
include "db.php";
$username=mysql_real_escape_string(htmlspecialchars(trim($_GET['username'])));
$query = mysqli_query($con, "SELECT * FROM member WHERE username = $username");
$json = array();
$no = 0;
while($row = mysqli_fetch_assoc($query)){
$json[$no]['id_member'] = $row['id_member'];
$json[$no]['nama_member'] = $row['nama_member'];
$json[$no]['username'] = $row['username'];
$json[$no]['ewallet'] = $row['ewallet'];
$no++;
}
echo json_encode($json);
mysqli_close($con);
?>
答案 0 :(得分:-1)
我认为,当您的收藏中没有行时,您会收到此警告。所以你可以用mysqli_num_rows()命令检查它。