2012-06-29 67 views
0

試圖讓Android應用程序從MySQL數據庫中的數據時,我面臨的問題從MySQL中獲取數據DB

輸出是:

06-29 11:40:42.123: E/JSON(1426): {"tag":"getroute","success":1,"error":0,"products":[]}    

我想我面臨的問題是在我的PHP文件中(這是標籤的代碼):

if(. . .) 
{ 
    . . . 
} 
else if ($tag == 'getroute') 
{ 
    $endloc = $_POST['end']; 
    $op = $db->getRoutes($endloc); 

    if ($op) 
    { 
     $response["products"] = array(); 

     while($data= mysql_fetch_assoc($op)) 
     { 
      $product = array(); 
      $product ["uname"] = $data["uname"]; 
      $product ["start"] = $data["start"]; 
      $product ["end"] = $data["end"]; 
      $product ["meet1"] = $data["meet1"]; 
      $product ["meet1time"] = $data["meet1time"]; 
      $product ["meet2"] = $data["meet2"]; 
      $product ["meet2time"] = $data["meet2time"]; 
      $product ["meet3"] = $data["meet3"]; 
      $product ["meet3time"] = $data["meet3time"]; 
      $product ["ismoke"] = $data["ismoke"]; 
      $product ["iwomen"] = $data["iwomen"]; 
      $product ["ctime"] = $data["ctime"]; 
      $product ["seats"] = $data["seats"]; 

      // push single product into final response array 
      array_push($response["products"], $product); 
     } 

     $response["success"] = 1; 

     echo json_encode($response); 

     // user stored successfully  
    } 
    else 
    { 
     // user failed to store 

     $response["error"] = 1; 
     $response["error_msg"] = "Error occured in Making Route"; 

     echo json_encode($response); 
    } 
} 

我不知道問題出在哪裏。我在互聯網上搜索,我發現一些教程,但他們總是給我這個錯誤。

功能getroute:

public function getRoutes($endlocation) 
{ 
    $result = mysql_query("SELECT * FROM routes WHERE end = '$endlocation'"); 

    return $result; 
} 
+0

你在Android代碼或PHP代碼中遇到錯誤嗎? – sunil

+0

我認爲這不是一個本機應用程序,你用什麼來構建應用程序,例如phonegap(不支持php) –

+0

@snuil不,我不會面對任何錯誤 – user1490693

回答

0

嘗試檢查與mysql_num_rows()結果的數量您開始前一陣。

此外,在此之後立即嘗試使用print_r($data)來驗證記錄中是否有內容。

在我看來,你只是有問題與您的數據源。

+0

你能澄清一下代碼? – user1490693