我有以下代码;
// check phone exist or not
$query = "SELECT * FROM user WHERE phone_number=".$phone;
$result = mysqli_query($conn,$query);
$count = mysqli_num_rows($result);
if($count!=0){
$error = true;
$phoneError = "Provided Phone Number($phone) is already in use.";
}
如何将查询结果作为json feed发送给我们同一个项目的同事?
答案 0 :(得分:0)
您需要创建一个数组,您可以在其中添加fail/success
等状态以及基于此的相应消息。
下面给出了一个示例代码: -
$final_message = [];
if($count > 0){
$final_message['status'] = 'fail';
$final_message['message'] = "Provided Phone Number($phone) is already in use.";
}else{
$final_message['status'] = 'success';
}
echo json_encode($final_message);