This is an AJAX response page. Someone told me that the JSON returned is a dump and not a proper formatted JSON object.
It is possible that it is just encoding every row from the $result query and not an whole JSON formatted object.
My question is how to put each row into an encoded JSON object for returning to Jquery?
I'm not clear on the difference between fetch_assoc and fetch_object? but why do they say it is not properly formed JSON object?

$mysqli = new mysqli($dbhost,$dbuser, $dbpass, $dbname,$dbport);
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}
echo 'Success... ' . $mysqli->host_info . "\n";




$sql = 'SELECT todo,date,name FROM task WHERE todo IS NOT NULL || todo > "" ';
$result = $mysqli->query($sql);

if($result = $mysqli->query($sql)) {

$i= 0;
	while($row = $result->fetch_object()) {

 $function_result[$i]= 	$row;
$i++;

	}	//end while
$result->close();

}//end i

$mysqli->close();
var_dump(json_encode($function_result));

I also tried it with

 printf("%fs %s %s \n",$obj->todo, $obj->date, $obj->name);

But I didn' know how to encode_json with the formatting and I think also that it gave me an error becuause it tried to cast to an int for some reason.
thanks

    jrough;11009489 wrote:

    Someone told me that the JSON returned is a dump and not a proper formatted JSON object.

    Well yes, you are [man]var_dump/man'ing the return value of [man]json_encode/man rather than simply outputting it.

      Write a Reply...