I normally get all JSON data using Jquery however I currently need to do it using only PHP.
Essentially this is how I normally get and output it with Jquery: (Snippet, not whole code)
$.post('getdata.php', {uid:uid} , function(data){
if(data){
$.each(data, function(key, data) {
$('#div #span-'+key).html(data);
});
}
} , 'json')
Where uid is the value passed to php for use in querying the database.
And this is the php back end: (Again just a snippet of the JSON section)
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$ret["ID"] = $row['id'];
$ret["username"] = $row['username'];
$ret["email"] = $row['email'];
$ret["age"] = $row['age'];
echo json_encode($ret);
}
And obviously on the output page along with jquery I initiate the class and function:
$class = new retrieveData();
$class->userDetails();
Then to output the individual parts of the array where I want I would create a span with the same unique key for the particular array part as set out in jquery.
How would I go about converting the jquery part of this into PHP?