php - 添加另一列到 ajax 下拉列表

标签 php jquery mysql ajax

我有一系列链接的选择,它们是通过调用 MySQL 数据库动态填充的。

This works great but I have to add another column 'Invm_InventoryDesc' to the label but keep the value the same (Invl_InventoryNumber) for each option in one of the selects.

I tried to alter the query to include the Invm_InventoryDesc but it breaks it...what am I doing wrong?

default:
    if (strpos($key, 'brandSelect-') === 0) {
        $callType = str_replace('brandSelect-', '', $key);
        $resBrands = mysql_query('SELECT Invl_InventoryNumber FROM ' . DB_TABLE1
            . ' WHERE Invl_LocationId  = ' . mysql_real_escape_string($callType) . " ORDER BY Invl_InventoryNumber");
        $select = new SelectBox('What part number are you looking for?', 'Pick a part');
        for ($i = 0; list($brand) = mysql_fetch_row($resBrands); $i++) {
            $select->addItem($brand, 'result-' . $brand . '-' . $callType);
        }

最佳答案

由于您没有分享执行代码时遇到的实际 php 错误,我只能猜测出了什么问题。

我发现您错误地使用了 for 语句。

我会建议这样的事情,而不是你当前的 for 循环:

for ($i = 0; $i < mysql_num_rows($resBrands); $i++) {
    $brand = mysql_fetch_array($resBrands);
    $select->addItem($brand, 'result-' . $brand . '-' . $callType);
}

现在 for 语句实际上做了一些事情。

$i 计算我们已经添加到 $select 的行数。一开始是 0“$i = 0”。

之后我们检查我们已经添加的行数是否小于我们需要添加的行数(mysql返回的行数)。

然后我们将一行加载到$brand。并将其添加到 $select。 (我不知道你在用 $brand 和 $select 做什么,所以我坚持你的代码。)

在此之后,我们向 $i 加一。我们重新开始

您的代码中可能存在更多错误。但如果没有更多上下文,我无法判断是否还有更多错误。

关于php - 添加另一列到 ajax 下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12860494/

相关文章:

mysql - Mysql中如何动态创建一个以主表字段为名的表?

php - 多服务器文件存储和共享导致网站挂起 - 同一服务器上的其他网站仍然可以访问

javascript - jQuery .load 导入特殊字符

javascript - 在谷歌分析中跟踪 facebook 评论小部件的最佳方法是什么?

php - Google Chart Api 使用日期时间值

mysql - PHP 防止 MySQL 竞争条件

javascript - PHP 使用 imagecreatefromstring 将 SVG 字符串转换为图像

javascript - 将 echo 值从 php 页面传递到 javascript 显示垃圾数据

php - PHP MYSQL 中的后续脚本自动更新

jquery - $.ajax() 函数内部的返回值