这是我的 php 读取数据库文件:
<?php
// read_My_Task.php
/*
* Following code will get single task details
* A task_detail is identified by task id (cid)
*/
// 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
if (isset($_GET["cid"])) {
$cid = $_GET['cid'];
// get a task from my-task table
$result = mysql_query("SELECT *FROM my_task WHERE cid = $cid");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$my_task = array();
$my_task["cid"] = $result["cid"];
$my_task["cus_name"] = $result["cus_name"];
$my_task["contact_number"] = $result["contact_number"];
$my_task["ticket_no"] = $result["ticket_no"];
$my_task["task_detail"] = $result["task_detail"];
// user node
$response["my_task"] = array();
array_push($response["my_task"], $my_task);
// echoing JSON response
echo json_encode($response);
}
else {
// no task found
$response["success"] = 0;
$response["message"] = "No task found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no task found
$response["success"] = 0;
$response["message"] = "No task found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
数据库有很多数据,但总是显示结果“{“成功”:0,“消息”:“缺少必填字段”}”
如何显示保存在 MySql 数据库中的数据