我正在尝试在php页面上打印user_reg表的所有用户。我也想使用名为$ data的数组进行检索。怎么办?
$result = mysqli_query($conn, "SELECT * FROM user_reg ORDER BY id ASC");
$data = array(
'statusCode' => 200,
'message' => 'Data retrived successfully'
);
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
echo json_encode($data);
答案 0 :(得分:0)
您正在编写$data
数组
$result = mysqli_query($conn, "SELECT * FROM user_reg ORDER BY id ASC");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
// write the status to a sub array
// dont destroy what you have already loaded into that array
$data['status'] = array(
'statusCode' => 200,
'message' => 'Data inserted successfully'
);
echo json_encode($data);