inc/ajax.php
This PHP script will generate and display the options for the global select box from a MySQL table depending on the action command parameter sent in. For example, when the GET parameter a, representing the action command, is set to ‘lopt_airports’:
ajax.php?a=lopt_airports
or
$_GET['a'] = 'lopt_airports';
the function lists all the records in the airports table using the get_read_sql() function in the inc/read.php file.
SELECT * FROM 'tbl_airports' WHERE 1
<?php
// get the connection
require('conn.php');
// get the crud functions
require('read.php');
// get the support functions
require('support.php');
// initialise the result string
$result = '';
// get the action from the get parameter
$action = mysql_real_escape_string($_GET['a']);
// the selected value
$sel_val = mysql_real_escape_string($_GET['sval']);
//$src = mysql_real_escape_string($_GET['src']);
switch ($action)
{
case 'lopt_lang':
$result = select_box('tbl_lang', 'lang_id', 'lang_name', $sel_val, $conn);
break;
case 'lopt_airports':
$result = select_box('tbl_airports', 'airport_id', 'airport_desc', $sel_val, $conn);
break;
case 'lopt_aoc':
$result = select_box('tbl_aoc', 'aoc_id', 'aoc_desc', $sel_val, $conn);
break;
case 'lopt_states':
case 'list_options_states':
$result = select_box('tbl_states', 'state_id', 'state_name', $sel_val, $conn);
break;
default:
$result = 'No resource was returned!';
}
// show the result
echo $result;
?>
To test if the ajax.php script is working enter the following into the browser
path/to/app/inc/ajax.php
You should see the result below
0 likes