2

我有以下 ajax 片段链接 2 个选择框,并使用 mysql 表中的值动态填充。

如果 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();
4

1 回答 1

0

@roryok 回答了这个问题,但没有办法给予评论?

$select->addItem('\'' . $callType . '\'', 'brandSelect-' . $callType);
于 2012-08-25T11:08:14.900 回答