PHP 帮助构建查询 [英] PHP help with building query
本文介绍了PHP 帮助构建查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个下拉列表,如果没有选择任何选项,则值为 = ""...
I have several drop lists where if no option is selected then the value is = ""...
我不知道如何在 PHP 中为 mysql 构建查询.
I cant figure out how to build the query for mysql in PHP.
查询 = SELECT * FROM db
query = SELECT * FROM db
推荐答案
我假设您有这样的选择:
I assume you have a select like this:
<select name="data[]" multiple="multiple">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
您的 php 可能类似于
Your php can be something like
<?php
$data = array();
$data = $_POST['data'];
$query = "select * from table";
if (count($data > 0)) {
for ($i = 0; $i < count($data); $i++) {
$data[$i] = "'{$data[$i]}'";
}
$query .= " where field in (".implode(",", $data).")";
}
这篇关于PHP 帮助构建查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文