2
我有以下ajax代碼片段,鏈接2個選擇框,並使用mysql表中找到的值動態填充。chained select ajax call only only works if value is a numbers
如果callType列是一個數字值,比如我的數據列SPG_CallType中找到的數值,那麼這很有用。當我改變這個使用聯繫字母的字段時,它會打破它。我假設這是因爲代碼僅適用於數值?如何更新片段的這一部分以接受alpha或數字?
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();
這項工作? $ select-> addItem('\''。$ callType。'\'','brandSelect-'。$ callType); – roryok
是的,這是我最終做的或類似的事情。謝謝! –