简体   繁体   中英

Getting Data from MYSQL DB

I'm facing problems when trying to get data from a MySQL Database in an Android application

The output is:

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

I think the problem I'm facing is in my PHP file (this is the code of the tag):

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);
    }
}

I don't know where the problem is. I searched over the internet and I found some tutorials but they always give me this error.

Function getroute :

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

   return $result;
} 

Try checking the number of results with mysql_num_rows() before you begin your while.

Additionally, immediately after your while, try using print_r($data) to verify that there is stuff in your record.

It seems to me that you're just having issues with your data source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM