2014-07-15 115 views
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; 

感謝您的幫助。

+0

在while循環嘗試的var_dump($行),並發表您這裏輸出 –

+0

當我改變了PHP函數的代碼它的工作原理: – user1989872

回答

0

當我更改PHP函數代碼的作品。我認爲一些sql語法不能工作。當我鍵入上面的查詢和新的查詢都返回從MySQL SQL編輯器相同的值,但是當我使用IN和任何單詞上面的SQL查詢它不工作在PHP功能JSON代碼。

這是我的新查詢:

public function getFriendsLocations($user_email) { 

     $result = mysql_query("select t1.user_email,t1.and_loc_lat, t1.and_loc_long, t1.and_loc_time, t1.and_loc_timezone, t1.and_sync_time, t1.user_loc_status FROM tbl_currentlocs t1 INNER JOIN tbl_friendship t2 ON t1.user_email=t2.friend_email AND t2.user_email='$user_email'"); 


     return $result; 

} 
相關問題