我研究了很多,找到了一些解决方案,可能不是me.Hence的令人信服的解决方案。我贴出了这个问题,请帮助我
我有一个具有相同名称和不同值的复选框,例如
1.cate.php
<form action="mobile-phones-category.php" method="post">
<input type="checkbox" value="samsung" name="mobile[]"> sams
<input type="checkbox" value="nokia" name="mobile[]"> nolkia
<input type="submit" name="submit" value="SUBMIT" class="btn btn-primary pull-right">
</form>
2.)mobile-phones-category.php
我检索了submitarray格式的复选框值,并希望从db中进行搜索。我使用的是普通mysql_query(而不是pdos)。
$search=$_POST["mobile"]; $search_string = implode(', ', $search); echo $search_string;
在这里我得到了像诺基亚,萨姆斯这样的东西
接下来,我将编写一个sql查询include('connection.php');。
$query = mysql_query("SELECT * FROM tablename where titles like '%$search_string%' ") or die(mysql_error());
发生的情况是,只搜索数组中的一个值,而不是array..What中的所有值都应该进行更改,以便搜索所有数组元素
感谢并致以问候
发布于 2013-08-08 14:59:03
在查询中使用IN关键字而不是LIKE
$query = mysql_query("SELECT * FROM tablename where titles IN ($search_string)" ) or die(mysql_error());使用示例:
$query = mysql_query("SELECT * FROM tablename where titles IN ('Nokia','Sams')" ) or die(mysql_error());这将从表中给出标题为Nokia & Sams的记录。
发布于 2013-08-08 15:01:14
正如User016所说,我也推荐使用IN语句。它搜索多个搜索词,这些搜索词由一个,分割。
你可以在这里找到文档:http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_in
https://stackoverflow.com/questions/18119735
复制相似问题