我正在按主要类别打印子类别ID和名称。我在此表中将mscategory_id作为foreign键。所以我与前键匹配并以json格式返回。在我的数据库中,我有针对1个主要类别的图标。执行后,我得到空值。
<?php
require 'conn.php';
require 'headers.php';
$method=$_SERVER['REQUEST_METHOD'];
if($method == "GET"){
$id=$_GET['mscategory_id'];
$sql = "SELECT sscategory_id, sscategory_name FROM t_srv_sscategory WHERE mscategory_id='$id' ";
$result = mysqli_query($conn,$sql);
$response=array();
if (!empty($result)) {
// check for empty result
if (mysqli_num_rows($result) > 0) {
$result = mysqli_fetch_array($result);
$user = array();
$user["sscategory_id"] = $result["sscategory_id"];
$user["sscategory_name"] = $result["sscategory_name"];
// success
$response["success"] = 1;
// user node
$response["user"] = array();
array_push($response["Sub Category Services"], $user);
// echoing JSON response
echo json_encode($response);
}
else {
// no user found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}}
else {
// no user found
$response["success"] = 0;
$response["message"] = "Credentials Error";
echo json_encode($response);
}
}
else {
$json["error_msg"] = "Required parameters (phone or password) is missing!";
echo json_encode($json);
$conn->close();
}
?>