0
在android編程時,我使用jsonarray時,我鍵入簡單查詢它的工作原理,但母雞我鍵入查詢PHP功能它返回錯誤:可捕捉的致命錯誤:類stdClass的對象無法轉換爲字符串,因爲mysql查詢
PHP代碼:
session_start();
$friendlocs=$db->getFriendsLocations($_SESSION['email']);
$a=array();
$b=array();
if ($res){
while ($row = mysql_fetch_array($friendlocs))
{
//$b["id"] = $data[$j]->id;
$b["f_name"] = $row[0];
$b["f_email"] = $row[0];
$b["f_lat"] = $row[1];
$b["f_lon"] = $row[2];
$b["f_time"] = $row[3];
$b["f_timezone"] = $row[4];
$b["f_synctime"] = $row[5];
$b["f_friend_status"] = $row[6];
array_push($a,$b);
}
}
echo json_encode($a);
PHP函數和查詢:
public function getFriendsLocations($user_email) {
// THIS QUERY RETURNS ERROR BUT IF I RUN THIS QUERY IN MYSQL EDITOR, IT WORKS
$result = mysql_query("select user_email,and_loc_lat, and_loc_long, and_loc_time, and_loc_timezone, and_sync_time, user_loc_status FROM tbl_currentlocs WHERE user_email = ANY (select DISTINCT friend_email FROM tbl_friendship WHERE user_email = '$user_email')");
//IF I USE result2 query it works on php and JSON
$result2 = mysql_query("select user_email,and_loc_lat, and_loc_long, and_loc_time, and_loc_timezone, and_sync_time, user_loc_status FROM tbl_currentlocs"); // WHERE user_email = '$user_email'
return $result;
感謝您的幫助。
在while循環嘗試的var_dump($行),並發表您這裏輸出 –
當我改變了PHP函數的代碼它的工作原理: – user1989872