I'm trying to figure out how to use jQuery's .ajax()
to query a MySQL table and return the results as an array. This is what I have so far:
jQuery:
$.ajax({url: 'procedures?',
data: {Action: 'GetSuggestList' },
dataType: "json",
success: function(oData){
if(oData.errormsg != null)
alert('failed: ' + oData.errormsg);
alert(oData.results);
}});
PHP code (with the assumption that my mysql_connect()
and mysql_select_db()
are valid):
$pcAction = isset( $_REQUEST['Action'] ) ? $_REQUEST['Action'] : "" ;
if($pcAction=='GetSuggestList'){
$tb_name = 'suggestions';
echo json_encode( DoGetSuggestList($tb_name) ) ;
}
function DoGetSuggestList($ptb_name){
$qry_suggest = mysql_query('SELECT * FROM ' . $ptb_name . ' WHERE Active ORDER BY updated DESC');
$rsl_suggest = mysql_fetch_array($qry_suggest);
$jSONreturn = array("errormsg" => $jSONerror, "results" => $rsl_suggest);
return $jSONreturn;
};
I'm not sure what else needs to be in my AJAX success function in order to iterate through each resulting row in the array...