Tuesday, May 8, 2012

getJSON + json_encode + query php

This is my query.php



<?php
$db_host="localhost";
$db_user="root";
$db_pass="root";
$db_name="mytable";

mysql_connect("$db_host","$db_user","$db_pass")or die("");
mysql_select_db("$db_name")or die("");

$query = "SELECT * FROM app";
$result=mysql_query($query);
echo json_encode(mysql_fetch_assoc($result));
?>


How can i do to learn any single attribute in my html page?
I try like this but it dont work.



$.getJSON("query.php",function(result){
$.each(result, function(i, obj){
$('div').html(obj.attribute1+" "+obj.attribute2 ecc...);
});
});




No comments:

Post a Comment