Update: I have completed my php code that ajax will access. I have read tutorials out the wazoo and think I have come up with my ajax call. I need to populate a new drop down with the returned code from the php file. Having a hard time understanding how to get the information out of the returned array and jsdon decoded no to loop through the information and create the drop downs I guess with javascript now? Here is the code so far:
Jquery ajax function:
<script id="source" language="javascript" type="text/javascript">
jQuery(function ()
{
//-----------------------------------------------------------------------
// 1) Send a http request with AJAX
//-----------------------------------------------------------------------
jQuery.ajax({
url: 'ajax/appointment_ajax_1.php', //the script to call to get data
data: "dealer_id = " + jQuery('dealer_id').val(), //you can insert url argumnets here to pass to api.php
//for example "id=5&parent=6"
dataType: 'json', //data format
success: function(data) //on recieve of reply
{
var first = data[0]; //get firstname
var last = data[1]; //get lastname
var id = data[2]; //get id
//--------------------------------------------------------------------
// 2) Update Dealer's Staff Select Box
//--------------------------------------------------------------------
jQuery('#output').html("<option name = 'name' value = "+id+">"+first+" "+last"</option>"); //Set option value and display
}
});
});
</script>
And here is the php file:
<?php
//--------------------------------------------------------------------------
// php/ajax script for onchange from add appointments
//--------------------------------------------------------------------------
session_start();
//--------------------------------------------------------------------------
// 1) Connect to mysql database
//--------------------------------------------------------------------------
include("../include/db_connect.php");
//--------------------------------------------------------------------------
// 2) Query database for data
//--------------------------------------------------------------------------
// Create container array
$dealer_staff_array = array();
$franchise_id = $_SESSION['franchise_id'];
$dealer_id = $_POST['dealer_id'];
$SQL = "SELECT * FROM login WHERE franchise_id = '$franchise_id' and dealer_id = '$dealer_id' ORDER BY name ASC";
$result = mysql_query($SQL) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
//--------------------------------------------------------------------------
// 3) echo result as json string
//--------------------------------------------------------------------------
$response = array(
'first' => $row['first'],
'last' => $row['last'],
'id' => $row['id']
);
array_push($dealer_staff_array, $response);
}
echo json_encode($response);
?>
Any help would be appreciated. Thanks
Snowdog