I am running a simple script to get data from mysql into select box but it doesn't fetch any data. below is the code :
<body>
Team : <select id="teamname"> </select> <br />
Members : <select id="members"> </select>
</body>
Jquery :
$("document").ready(function(){
$.getJSON("ajax.php", function(data){
$("#teamname").empty();
$.each(data.result, function() {
$("#teamname").append("<option>" + this('team_name') + "</option>");
});
});
PHP
$result=array();
$getteams=mysql_query("select * from tbl_teams");
if(mysql_num_rows($getteams)){
while($gotteams=mysql_fetch_array($getteams)){
array_push($result,array('id' => $gotteams['team_id'],
'name' => $gotteams['team_name']));
}
echo json_encode(array('result' => $result));
}
I tried everymeans and every other example available online but still doesn't work. Please help me.