i have a problem in query
i have attached a sql for query and my searching code is following

<form name="frm" action=search.php method=post>
  <select name="facilities[]" id="facilities[]" style="width: 130px;" multiple="mutiple" size="3">
    <option value="17">Conference hall</option>
    <option value="16">Meeting</option>
    <option value="14">Danceing</option>
    <option value="15">Swimming</option>
    <option value="18">A/c room</option>
    <option value="19">Dining hall</option>
    <option value="20">Cooking facility</option>
    <option value="21">Gardening</option>
    <option value="22">Tempels</option>

below is my php code i want to search host which have multiple facilities
means search a host have 17 and 16 facilities
or search a host have 15 and 16 facility

foreach ($_POST['facilities'] as $item){
$comma_separated = implode(",", $facilities);
if(isset($_POST['facilities']) && (sizeof($facilities) !='0'))
					  $where.= " where facility in (".$comma_separated.")";
$kkc="select * from tblhost " .$where;

but i could not find proper result for it

6 Years
Discussion Span
Last Post by Shanti C

i checked your code,
your facility field contains 17,16,14,15.
Means these values are not in sorted order. that is the problem..
sort the array while inserting the facility column.

why because mysql IN() function works based on binary search.
binary search needs to be searched array in sorted manner.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.