2
2 개의 선택 상자를 연결하고 mysql 테이블에있는 값을 사용하여 동적으로 채워진 다음 ajax 스 니펫이 있습니다.선택 아약스 호출은 값이 숫자 인 경우에만 작동합니다.
위의 코드는 callType 열이 데이터 열 SPG_CallType에있는 것과 같은 숫자 값인 경우 유용합니다. 알파벳 문자와 접촉하는 열을 사용하도록 변경하면 문자가 깨집니다. 코드가 단지 수치 값으로 작동하기 때문에 이것이라고 가정합니다. 스 니펫 부분을 알파 또는 숫자로 받아들이도록 어떻게 업데이트합니까?
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
그래, 내가 끝내거나 이와 비슷한거야. 감사! –