fetch data from sql into php array returns nothing

62
February 11, 2019, at 1:20 PM

I'm trying to json_encode the data that was fetched from SQL, however when i stored it into PHP array, it didn't return any value. Is there any code that i am missing or are there limits to the array?

I tried json_encod inside a loop but i need angular 4 to read the json file that was encoded from the php file. Also, i tried to check if the loop was working and it fetched the 56 rows from sql but when i put it into the PHP array, the array was displaying a blank php file.

/location.php (TRY1)

$sql = "SELECT * FROM api_locations";
$result = mysqli_query($con, $sql);
$outp = array();
if(mysqli_num_rows($result) > 0)
{
while($data = $result->fetch_assoc()){
    $location = $data['loc_name'];
    $feature = $data['feature'];
    $lat = $data['lat'];    
    $lng = $data['lng'];
    $desc = $data['description'];
    $hrs = $data['hrs'];
    $min = $data['min'];
    $rating = $data['rating'];
    $max_b = $data['budget_maximum'];
    $min_b = $data['budget_minimum'];

    $outp[] = array( 
        "location" => $location,
        "feature" => $feature ,
        "lat" => $lat ,
        "lng" => $lng ,
        "description" => $desc ,
        "hrs" => $hrs ,
        "min" => $min ,
        "rating" => $rating ,
        "budget_maximum" => $max_b ,
        "budget_maximum" => $min_b ,
    );
}   
echo json_encode($outp);
}

or i did the while loop the other way:

while ($data = mysqli_fetch_assoc($result)) {
$outp[] = $data;
}

NOTE: The $outp is still empty when doing json_encode.

I expect the output will be like this.

{"id":"1","loc_name":"Robinsons Magnolia","lat":"123.1321","lng":"12.213","feature":"Shopping","description":"Happy place to shop","hrs":"1","min":"30","rating":"4","budget_maximum":"5000","budget_minimum":"100"}

...

{"id":"56","loc_name":"CHICHIHC","lat":"213.1213","lng":"12.23131","feature":"Entertainment","description":"Good place to make kalokohan","hrs":"1","min":"30","rating":"4","budget_maximum":"100","budget_minimum":"50"}

But the real output was blank.

I also tried to do this

$sql = "SELECT *
     FROM api_locations WHERE id<=9";

And this works. totally! but when it exceeds from 9. still not working.

READ ALSO
How to have recursive tree genealogy in symfony

How to have recursive tree genealogy in symfony

I'm making tree genealogy in symfony

52
PHP Subscribe Form with Email Duplicate Check

PHP Subscribe Form with Email Duplicate Check

I'm very new to PHP and struggling with adding in duplicate email check with this code

51
Send Message to Telegram Bot Without Open Telegram Apps

Send Message to Telegram Bot Without Open Telegram Apps

usually if we want to chat or send command to Telegram Bot, we just texting the bot from Telegram apps (desktop, web, or smartphone)Is there any way texting the bot without open Telegram apps?? I've read many website and thread in stackoverflow, but no clue

99
htaccess file is not working properly in Laravel on linux

htaccess file is not working properly in Laravel on linux

I'm working on a Laravel projectI'm Removing "/public" from URL but it's only work on welcome page, other page like /login,/register is doesn't work properly

81