0

I researched a lot and found some solution ,probably not a convincing solution for me.Hence i am posting this question,Please help me

I Have A checkbox with same name and different values like

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

I retrieve the values of check box on submit[array format] and want to search from db..I am using normal mysql_query(not pdos)

$search=$_POST["mobile"]; $search_string = implode(', ', $search); echo $search_string;

Here i Get something like Nokia,Sams

Next I write a single sql query include('connection.php');

$query = mysql_query("SELECT * FROM tablename where titles like '%$search_string%' ") or die(mysql_error());

What is happening is that only one value in the array is searched and not all the values in array..What changes should i Make so that all the array element should get searched

Thanks and regards

4

2 回答 2

1

在查询中使用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-08T06:59:03.460 回答
0

就像 User016 说的,我也推荐使用 IN 语句。它搜索几个搜索词,由,.

你可以在那里找到文档:http: //dev.mysql.com/doc/refman/5.1/en/comparison-operators.html#function_in

于 2013-08-08T07:01:14.370 回答