SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    0 Post(s)
    0 Thread(s)

    Query Based On Multi-Select Dropdown

    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.

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="Test">
        <select name="p[]" size="10" style="width:170px" multiple="multiple" method="POST">
    			$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>"; 
        <input type="submit" name="unused" value="Post Selections" />
    		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) . ' )';
    					echo("<p>You didn't select any filters!</p>\n");
    					$nselections = count($selections);
    					echo("<p>$nselections filter(s) selected:<br>");
    					for($i=0; $i < $nselections; $i++)
    					echo($selections[$i] . "<br/>");
    					$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, 	
    					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)) {
    	<td><strong><a href='$row[RestPage]'>$row[RestName]</a></strong></td>
    	echo "</table><br />\n";
    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.
    Last edited by DS928; Feb 9, 2013 at 12:39. Reason: More Info

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts