i'm doing a website and now i need that a php class returns an array containing the result of a query in this mode with the key that is the name of the column on the db, and the value that is the value stored in db for that key. The result set contains only a row .
I'm trying in this mode .
$nomePG = $_POST['nomePG'];
$querys = mysqli_query($db_connect, "SELECT * FROM user WHERE nomeutente like '%$nomePG%'");
$queryRicerca = mysqli_fetch_array($querys);
$arrayReturn = array(); // This is the array to encode with JSON
$keys = array_keys($queryRicerca);
$i=0;
$count=count($keys);
while ($i < $count) {
$arrayReturn[$i]=$keys[$i]->$queryRicerca[$keys[$i]];
}
echo json_encode($arrayReturn);
... what am I doing wrong?
The SQL Query returns something like this :
Name : Mark Age : 13
And i want that in arrayReturn the key is Name and the value is Mark, for example ... and all must be in JSON format at the end ( with function json_encode ? ).
Thanks for your help!
print_r()
of the output array as it stands? – halfer Apr 12 at 16:09print_r
that really does help, though - still am not quite sure what you mean. Include a dump of what you get, and a dump of what you want. – halfer Apr 12 at 16:15