i set up a multi select form to return arrays and then looped them through mysql query to return results
i dont want duplicate results if the user selects multiple options and those
options are in one record
for example user selects three different ‘Views’ and one property has all three views i dont want that displayed in the results three times … thank you if you can help
require ('db.php');
$N = $_GET['Neigh'];
$V = $_GET['view'];
$C = $_GET['Con'];
$F = $_GET['front'];
$minPrice = $_GET['minprice'];
$maxPrice = $_GET['maxprice'];
$Year = $_GET['YearBuilt'];
foreach($N as $Nvalue){
if ($Nvalue != "\n\r" || $Nvalue != "" || $Nvalue !=NULL)
foreach($C as $Cvalue){
foreach($F as $Fvalue){
foreach($V as $Vvalue){
$query="SELECT *
FROM `foo`
WHERE `Building` LIKE '%{$Bvalue}%' && `Neigh` = '{$Nvalue}' && `View`
LIKE '%{$Vvalue}%' && `Con` LIKE '%{$Cvalue}%'
&& `front` LIKE '%{$Fvalue}%' && `Listprice` BETWEEN '{$minprice}' AND '{$maxprice}'
&& `Year_Built` >= '{$Year}' && `Status` LIKE '%Active%' GROUP BY `MLS`
ORDER BY `Neigh`, `price`, `tmk` ASC";
$result=mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />\n $query"); ;
$num=mysql_num_rows($result);
sorry if this is a mess .. im self taught from the internet .. it does work but returns duplicates for multiple variables in the same record …
If you want to keep the current design with view stored in a single cell, then there is something you can do. Although I do not suggest it I give an example below because you already have designed your project like this.
NOTICE: It is a testing example, to see the basic functionality. This is not final code cause sql injection and other things are not taken in consideration.
I do the assumption that views are stored in a single cell, space delimited, and if a view consist of more that one word – are place in between, for example City-Center.
Study this example and see if you can adjust it to your needs:
Although you see a some foreach loops, there is no need to worry cause they run for small arays that contain user data, so consider them runing super fast cause there is no mysql query involved!!
If any problem remains consider giving details on db schema and some basic description. Hope this can help!