population select option using json_encode-Collection of common programming errors
Can someone help me figure out why the json array I have is not population my select drop down? The array prints fine (name:value) and I have tried different ways (.post .getJSON) to fill the select fields. See my code below…
PHP
$q = "select Site_ID, FirstName, LastName from ClientInfo";
$sql = mysql_query($q);
$data = array();
while($row = mysql_fetch_array($sql, true)){
$data[] = $row;
};
echo json_encode($data);
This is what it prints on webpage:
[{"Site_ID":"10000001","FirstName":"drew","LastName":"0"}, {"Site_ID":"10000002","FirstName":"hello","LastName":"0"},{"Site_ID":"10000003","FirstName":"hihi","LastName":"0"},{"Site_ID":"10000004","FirstName":"","LastName":"0"},{"Site_ID":"10000005","FirstName":"SueAnn","LastName":"Hall"},{"Site_ID":"10000006","FirstName":"Test","LastName":"Name"}]
HTML with script
$(function(){
$.getJSON('checkin.php',function(data){
$.each(data,function(name,value)
{
items+=""+item.name+"";
});
$("#clients").html(items);
});
});
Default
Works fine until I run the html. Thank you in advance for your help.