I have the following ajax snippet that chains 2 select boxes and is populated dynamically using values found in a mysql table.
This works great if the callType column is a numerical value like what is found in my data column SPG_CallType. When I change this to use a column that contact alphabetical letters it breaks it. I am assuming this is because the code works for just numerical values? How do I update that part of the snippet to accept either alpha or numeric?
if (isset($_GET['key'])) {
$key = $_GET['key'];
switch ($key) {
case 'callTypeSelect':
$select = new SelectBox('Repair Type?','Choose a category');
$res = mysql_query('SELECT DISTINCT SPG_CallType FROM ' . DB_TABLE . ' ORDER BY SPG_CallType ASC');
$callTypes = array();
for ($i = 0; list($callType) = mysql_fetch_row($res); $i++) {
$callTypes[] = $callType;
$select->addItem($callType, 'brandSelect-' . $callType);
}
header('Content-type: application/json');
echo $select->toJSON();
break;
default:
if (strpos($key, 'brandSelect-') === 0) {
$callType = str_replace('brandSelect-', '', $key);
$resBrands = mysql_query('SELECT SPG_Brand FROM ' . DB_TABLE
. ' WHERE SPG_CallType = ' . mysql_real_escape_string($callType) . ' ORDER BY SPG_Brand ASC');
$select = new SelectBox('Choose a Manufacturer', 'Pick a brand');
for ($i = 0; list($brand) = mysql_fetch_row($resBrands); $i++) {
$select->addItem($brand, 'result-' . $brand . '-' . $callType);
}
header('Content-type: application/json');
echo $select->toJSON();
@roryok answered the question, no way to give credits to comment though?