I currently have this code which reads the first field in a database record which is specified by the user ('myid' being a text field which accepts a number) and prints it in one of the fields of a front end form.
How do I make a JSON array of all of the fields in the database and then print them to the relevant form field? Thanks
Back-End Code
$id = $_POST['id'];
$query = "SELECT * FROM Customers WHERE ID = '" . mysql_real_escape_string($id) . '"';
$result= mysql_query($query);
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_row($result)) {
echo $row[1];
}
}
else {
// no
// print status message
echo "No rows found!";
}
Front-End Code
jQuery(document).ready(function(){
jQuery("input.myid").keyup(function(e){
e.preventDefault();
ajax_search();
});
});
function ajax_search(){
var search_val=jQuery("input.myid").val();
jQuery.post("find.php", {id : search_val}, function(data){
jQuery("input.fname").val(data);
}
)}