I am trying to run a query based on a multi-select dropdown.. I have the dropdown built. I am getting the values that are selected, but I am not getting the results, I think its in the query. Also the page is reloading, which is not good! Here is what I have so far.
The results are to be based on result AND result AND result etc..... Not result OR result OR result etc... There are 42 selections and all of them can or cannot be selected. Thank you.Code:<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="Test"> <select name="p[]" size="10" style="width:170px" multiple="multiple" method="POST"> <?php error_reporting(E_ALL); include("config.php"); $sql = "SELECT tblDetails.DetailType AS type, GROUP_CONCAT(DISTINCT DetailName ORDER BY DetailName ASC SEPARATOR '|') AS DetailName FROM tblLocations INNER JOIN (tblLocDet INNER JOIN tblDetails ON tblLocDet.DetailID = tblDetails.DetailID) ON tblLocations.LocationID = tblLocDet.LocationID GROUP BY tblDetails.DetailType,tblLocations.CityID,tblLocations.AreaID,tblLocations.CuisineID HAVING (((tblLocations.CityID)='16') AND ((tblLocations.AreaID)='131') AND ((tblLocations.CuisineID)='3'))"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<optgroup label='{$row['type']}'>"; $DetailNames = explode('|', $row['DetailName']); foreach($DetailNames as $DetailName) { echo "<option value='".$DetailName."'>".$DetailName."</option>"; } echo "</optgroup>"; } ?> </select> <input type="submit" name="unused" value="Post Selections" /> </form> <?php include("config.php"); if (!empty($_POST)) { $selections = ($_POST['p']); foreach ($selections as $key => $value) { $selections[$key] = trim($value); if (empty($selections[$key])) unset($selections[$key]); } if (empty($selections)) die('No Selection'); $where = 'WHERE ( ' . implode(' AND ', $selections) . ' )'; print_r($where); ?> <?php if(!isset($selections)) { echo("<p>You didn't select any filters!</p>\n"); } else { $nselections = count($selections); echo("<p>$nselections filter(s) selected:<br>"); for($i=0; $i < $nselections; $i++) { echo($selections[$i] . "<br/>"); } echo("</p>"); $DM = implode(',',$selections); if(!$rs=mysql_query("SELECT tblRestaurants.RestName, tblDetails.DetailName, tblLocations.CityID, tblLocations.AreaID, tblLocations.CuisineID, tblLocations.RestID, CONCAT(tblLocations.StreetNumber,' ', tblLocations.Street) Address,tblRestaurants.RestPage, tblLocations.StreetNumber, tblLocations.Street, tblLocations.Phone, tblLocations.Price, tblLocations.Rating FROM tblDetails INNER JOIN tblRestaurants INNER JOIN tblLocations ON tblRestaurants.RestID = tblLocations.RestID INNER JOIN tblLocDet ON tblLocations.LocationID = tblLocDet.LocationID ON tblDetails.DetailID = tblLocDet.DetailID WHERE tblLocations.tblCityID = '16' AND tblLocations.AreaID ='131' AND tblLocations.CuisineID = '3' AND tblDetails.DetailName = '$_POST('$selections') ORDER BY tblRestaurants.RestName;")) { echo "Cannot parse query"; } elseif(mysql_num_rows($rs) == 0) { echo "No records found"; } else { echo "<table id=\"myTable\" table width=\"710\" class=\"beautifuldata\" align=\"Left\" cellspacing=\"0\">\n"; echo "<thead>\n<tr>"; echo "<th>PLACE</th>"; echo "<th>ADDRESS</th>"; echo "<th>PHONE</th>"; echo "<th>PRICE</th>"; echo "<th>RATING</th>"; echo "</tr>\n</thead>\n"; while($row = mysql_fetch_array($rs)) { echo"<tr> <td><strong><a href='$row[RestPage]'>$row[RestName]</a></strong></td> <td>$row[Address]</td> <td>$row[Phone]</td> <td>$row[Price]</td> <td>$row[Rating]</td> </tr>\n"; } echo "</table><br />\n"; } } } ?>


Reply With Quote

Bookmarks