ANDROID / PHP: Spinner cannot populate data from MySQL-ThrowExceptions

Exception or error:

Currently, I created android apps that have a spinner. This spinner populated data from MySQL. For now, the spinner can list all the data. Below is my current code:

spinner_factory.php

<?php 

    include("../config/configPDO.php");
    include("../config/api/api.php");

    $query = $conn->prepare("SELECT * FROM ot_factory ORDER BY fac_id ASC");
    $query->execute();

    // $query = callApi9();

    $factoryList = array();

    while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
        array_push($factoryList,array(

            'fac_name'=>$row['fac_name'],

            )
        );
    }

    echo json_encode(array('result'=>$factoryList));

?>

Now, I want to change the query format to JSON. The Api as follows:

api.php

<?php

    function callApi9(){
        $url = "http://172.20.0.45/TGWebService/TGWebService.asmx/ot_displayFactory?";
        $data = file_get_contents($url);
        $json = json_decode($data);
        return $json->otFactoryList;
    }

?>

Can I know how to implement this “api.php” into “spinner_factory.php”

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *