0

I'm trying to retrieve an array from my database, but keep getting returned NULL values or nothing at all.

I have tried converting the entire database with UTF-8 unicode, numerous different methods, and hosting sites.

The response i am getting with print_r and json_encode is as follows:

Array
(
[success] => 
[0] => Array
    (
        [lat] => 
        [lng] => 
        [value] => 
    )

[1] => Array
    (
        [lat] => 
        [lng] => 
        [value] => 
    )

[2] => Array
    (
        [lat] => 
        [lng] => 
        [value] => 
    )

[3] => Array
    (
        [lat] => 
        [lng] => 
        [value] => 
    )

[4] => Array
    (
        [lat] => 
        [lng] => 
        [value] => 
    )

)

0No error{"success":false,"0":{"lat":null,"lng":null,"value":null},"1"{"lat":null,"lng":null,"value":null},"2":{"lat":null,"lng":null,"value":null},"3":{"lat":null,"lng":null,"value":null},"4":{"lat":null,"lng":null,"value":null}}

My php code:

<?php
header('Content-Type: application/json');
$con = mysqli_connect("aaa", "bbb", "ccc", "ddd");

//Sets charset for JSON parsing
//no need anymore, database is utf8_unicode_ci already
//$charset = mysql_query("SET CHARACTER SET utf8");
//utf8_encode($arrItem);

$statement = mysqli_prepare($con, "SELECT * FROM markers    ORDER BY marker_id");
mysqli_stmt_execute($statement)  or die(mysqli_error($con));

$arrRows = array();
$arryItem = array();
$arrRows["success"] = false;
$arryItem["success"] = false;

mysqli_stmt_bind_result($marker_id,$lat,$lng,$value);

    while(mysqli_stmt_fetch($statement)) {
      $arrRows[] = compact('marker_id','lat','lng','value');
    }

    print_r($arrRows);
    echo json_last_error();
    echo json_last_error_msg();
    echo json_encode($arrRows);
?>  

The values supposed to be returned are these:

database values

All help is much appreciated, really need to solve this!

If there is something i didn't explain well enough or you need additional info, please let me know. I could post the other methods i tried for my while loop, but was told that using compact() was the most optimal way to do it.

1
  • Have you checked your error logs? Commented Nov 7, 2016 at 13:14

1 Answer 1

1

You need to pass $statement as the first argument to your mysqli_stmt_bind_result() call when using it in a procedural way.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that actually worked. I feel like an idiot now. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.