use*_*032 -1 php mysql select json
我有一个PHP代码,必须从mysql表中选择所有字段三个字段,但问题,结果只是2个字段如何修复此错误?
mysql表"用户"
的Fileds:
{"userlist":[{"id":"2","user":"user2"},{"id":"3","user":"michel"},{"id":"4","user":"georges"},{"id":"5","user":"testtest1"}],"success":1}
Run Code Online (Sandbox Code Playgroud)
<?php
/*
* Following code will list all the emp
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all emp from emp table
$result = mysql_query("SELECT *FROM users") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// emp node
$response["userlist"] = array();
while ($row = mysql_fetch_array($result)) {
$response["success"] = 1;
// temp user array
$userlist = array();
$userlist["id"] = $row["id"];
$userlist["user"] = $row["user"];
$userList["date"] = $row["date"];
//$response["message"] = $userList["create_date"];
// push single Employee into final response array
array_push($response["userlist"], $userlist);
}
// success
//$response["message"] = "DISPLAYED Success";
// echoing JSON response
echo json_encode($response);
} else {
// no emp found
$response["success"] = 0;
$response["message"] = "No User found";
// echo no users JSON
echo json_encode($response);
}
?>
Run Code Online (Sandbox Code Playgroud)
仔细看....
$userlist["id"] = $row["id"];
$userlist["user"] = $row["user"];
$userList["date"] = $row["date"];
Run Code Online (Sandbox Code Playgroud)
注意的情况下,$userlist和$userList?将最后一个更改为小写,它将正常工作.