【发布时间】:2016-05-24 11:35:05
【问题描述】:
我有一个选择框,我通过 ajax 将值传递给 mysql 语句。 我需要让它更智能一点,所以我不必硬编码选择框中的所有值
HTML 选择框是:
<select>
<option value="value1">something</option>
<option value="value2">somethingElse</option>
</select>
我通过 ajax 传递值:
var opts = [];
$selectboxes.each(function(){
opts.push($(this).val());
})
在我的 php 文件中,我使用该值来过滤 SQL 选择语句:
if (in_array("something", $opts)){
$where .= " AND region = 'something'";
}
如果用户选择选项 1,其值为 value1,则 php 文件应更改为类似
if (in_array("VALUE1", $opts)){
$where .= " AND region = 'VALUE1'";
}
【问题讨论】:
-
使用
id's和where in
标签: javascript php jquery mysql ajax