I am using json for the first time so this may be a bit of a stupid question.
My PHP code for returning json is as follows:
$query="SELECT * FROM user_db WHERE rest_id='$rest_id'";
$result=mysqli_query($dbc, $query);
$row=array();
while($r = mysqli_fetch_assoc($result)) {
$rows{'Users'][] = $r;
}
echo json_encode($rows);
This returns the following:
{"Users":
[{"user_id":"1361453832p3y","name":"","username":"sideshow","password":"sideshow","user_type":"1","rest_id":"1361453832fxL","email":""},
{"user_id":"1361523362ANq","name":"Sharon","username":"Sharon45","password":"Sharon45","user_type":"3","rest_id":"1361453832fxL","email":""},
{"user_id":"1361523653SXp","name":"Heather F","username":"fishface","password":"golliwog","user_type":"3","rest_id":"1361453832fxL","email":""}]}
All I am trying to do is to loop out the results and append them to the page.
My current JQuery is:
var name="";
var username="";
var password="";
var user_type="";
var output="";
var obj=$.parseJSON(html);
$.each(obj, function(){
output+="<p><strong>"+this['name']+"</strong></p>";
output+="<p>Username: "+this['username']+" Password: "+this['password']+"</p>";
output+="<hr />";
});
$('.user_holder').html(output);
This just echos out each field three times. I have not found a way to loop through each json field.....