gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 14:14:44 24 4
gpt4 key购买 nike

我有一系列链接的选择,它们是通过调用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com