我的代码
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
// get a product from products table
$result = mysql_query("SELECT *FROM druglist") ;
if (mysql_num_rows($result) > 0) {
$response["DrugList"]= array();
while($row=mysql_fetch_array($result)){
$DrugList = array();
$product["Drugs Name"] = $result["Drugs Name"];
$product["content"] = $result["content"];
$product["Type"] = $result["Type"];
$product["Company"] = $result["Company"];
// success
array_push($response["DrugList"],$DrugList);
}
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
}else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
?>
答案 0 :(得分:0)
Use below codes:
$DrugList["Drugs Name"] = $result["Drugs Name"];
$DrugList["content"] = $result["content"];
$DrugList["Type"] = $result["Type"];
$DrugList["Company"] = $result["Company"];
instead of
$product["Drugs Name"] = $result["Drugs Name"];
$product["content"] = $result["content"];
$product["Type"] = $result["Type"];
$product["Company"] = $result["Company"];