regoch Posted July 3, 2011 Share Posted July 3, 2011 Here is my real estate search form. <table width="300" border="0" cellspacing="0" cellpadding="0" style="background-color:#000000"> <form action="pretraga.php" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <tr> <td height="10"></td> </tr> <tr> <td height="35" class="title">Find real estate</td> </tr> <tr> <td height="10"></td> </tr> <tr> <td align="center"><select name="nekretnina_vrsta" id="nekretnina_vrsta" style="FONT-SIZE: 15px; WIDTH: 265px; background-color: #FFFFFF; FONT-COLOR: #FFFFFF; FONT-FAMILY: Arial, Helvetica, sans-serif" > <option value="" selected> Type:</option> <option value='1'>Apartment</option> <option value='3'>House</option> <option value='2'>Flat</option> </select></td> </tr> <tr> <td height="15"></td> </tr> <tr> <td align="center"><select name="nekretnina_lokacija" id="nekretnina_lokacija" style="FONT-SIZE: 15px; WIDTH: 265px; background-color: #FFFFFF; FONT-COLOR: #FFFFFF; FONT-FAMILY: Arial, Helvetica, sans-serif" > <option value="" selected> Location:</option> <option value='benkovac'>Benkovac</option> <option value='pakostane'>Pakoštane</option> <option value='ugljan'>Ugljan</option> <option value='ugljan-lucino'> Lučino</option> <option value='ugljan-susica'> Sušica</option> <option value='zadar'>Zadar</option> <option value='zadar-bokanjac'> Bokanjac</option> <option value='zadar-borik'> Borik</option> <option value='zadar-poluotok'> Poluotok</option> <option value='zaton'>zaton</option> </select></td> </tr> <tr> <td height="15"></td> </tr> <tr> <td align="center"><select name="nekretnina_cijena_ukupno" id="nekretnina_cijena_ukupno" style="FONT-SIZE: 15px; WIDTH: 265px; background-color: #FFFFFF; FONT-COLOR: #FFFFFF; FONT-FAMILY: Arial, Helvetica, sans-serif" > <option value="" selected> Price:</option> <option value="75000">do 75.000,00 EUR</option> <option value="100000">to 100.000,00 EUR</option> <option value="150000">to 150.000,00 EUR</option> <option value="200000">to 200.000,00 EUR</option> <option value="200000000">over 200.000,00 EUR</option> </select></td> </tr> <tr> <td height="15"></td> </tr> <tr> <td align="center"><select name="nekretnina_povrsina" id="nekretnina_povrsina" style="FONT-SIZE: 15px; WIDTH: 265px; background-color: #FFFFFF; FONT-COLOR: #FFFFFF; FONT-FAMILY: Arial, Helvetica, sans-serif" > <option value="" selected> Size:</option> <option value="0-100">to 100 m2</option> <option value="101-300">from 100 to 300 m2</option> <option value="301-500">from 300 to 500 m2</option> <option value="501-10000000">Over 500 m2</option> </select></td> </tr> <tr> <td height="15"></td> </tr> <tr> <td style="padding-left:20px"><input class="button" type="submit" name="trazilica" value=" Search "></td> </tr> <tr> <td height="20"></td> </tr></form> </table> Here is my php code. $nekretnina_vrsta=$_POST['nekretnina_vrsta']; $nekretnina_lokacija=$_POST['nekretnina_lokacija']; $nekretnina_cijena_ukupno=$_POST['nekretnina_cijena_ukupno']; $nekretnina_povrsina=$_POST['nekretnina_povrsina']; $range = $_POST['nekretnina_povrsina']; else { $pieces = explode('-', $range); $low = intval($pieces[0]); $high = intval($pieces[1]); $rezultat=mysql_query("SELECT * FROM nekretnine_ponuda WHERE nekretnina_vrsta='$nekretnina_vrsta' AND nekretnina_lokacija LIKE '%$nekretnina_lokacija%' AND nekretnina_cijena_ukupno <= $nekretnina_cijena_ukupno AND nekretnina_povrsina BETWEEN $low AND $high ORDER BY nekretnina_id DESC"); if ( mysql_num_rows( $rezultat ) == 0 ){ echo "nothing found"; } else {do query....} That's working fine, but boss now change his mind and wont to search form to search one, or two, or three fields, not all fields to be required. So I remove if ($nekretnina_vrsta=="") echo $trazilica_greska_1." <br />"; if ($nekretnina_lokacija=="") echo $trazilica_greska_2." <br />"; if ($nekretnina_cijena_ukupno=="") echo $trazilica_greska_3." <br />"; if ($nekretnina_povrsina=="") echo $trazilica_greska_4." <br />"; and change query from AND to OR $rezultat=mysql_query("SELECT * FROM nekretnine_ponuda WHERE nekretnina_vrsta='$nekretnina_vrsta' OR nekretnina_lokacija LIKE '%$nekretnina_lokacija%' OR nekretnina_cijena_ukupno <= $nekretnina_cijena_ukupno OR nekretnina_povrsina BETWEEN $low AND $high ORDER BY nekretnina_id DESC"); but got nothing showed. Just getting nothing found, Only when i select price range i get all real estates, with no matter what price is. Anybody got a idea? Quote Link to comment https://forums.phpfreaks.com/topic/241025-real-estate-search-engine-new-problem/ Share on other sites More sharing options...
mikesta707 Posted July 4, 2011 Share Posted July 4, 2011 looks ok to me. Without knowing your database structure or anything like that its hard to say what the problem is. Is there a mysql error? Quote Link to comment https://forums.phpfreaks.com/topic/241025-real-estate-search-engine-new-problem/#findComment-1238030 Share on other sites More sharing options...
regoch Posted July 4, 2011 Author Share Posted July 4, 2011 not showing any error, just when I select type of real estate show nothing. Only when I select price show all real estates without considering price range I select. Sorry about my english. Quote Link to comment https://forums.phpfreaks.com/topic/241025-real-estate-search-engine-new-problem/#findComment-1238031 Share on other sites More sharing options...
regoch Posted July 4, 2011 Author Share Posted July 4, 2011 I solve it with this code, not very pretty but working fine! Except they don't get real estate over 100.000.000.000,00 euro! $nekretnina_cijena_ukupno=$_POST['nekretnina_cijena_ukupno']; $nekretnina_vrsta=$_POST['nekretnina_vrsta']; $nekretnina_lokacija=$_POST['nekretnina_lokacija']; $nekretnina_povrsina=$_POST['nekretnina_povrsina']; if ($nekretnina_cijena_ukupno=="") $nekretnina_cijena_ukupno="nekretnina_cijena_ukupno <= 100000000000"; else $nekretnina_cijena_ukupno="nekretnina_cijena_ukupno <= $nekretnina_cijena_ukupno"; if ($nekretnina_vrsta=="") $nekretnina_vrsta=""; else $nekretnina_vrsta="AND nekretnina_vrsta='$nekretnina_vrsta'"; if ($nekretnina_lokacija=="") $nekretnina_lokacija=""; else $nekretnina_lokacija="AND nekretnina_lokacija LIKE '%$nekretnina_lokacija%'"; if ($nekretnina_povrsina=="") $nekretnina_povrsina=""; else{ $range = $_POST['nekretnina_povrsina']; $pieces = explode('-', $range); $low = intval($pieces[0]); $high = intval($pieces[1]); $nekretnina_povrsina="AND nekretnina_povrsina BETWEEN $low AND $high"; } $rezultat=mysql_query("SELECT * FROM nekretnine_ponuda WHERE $nekretnina_cijena_ukupno $nekretnina_vrsta $nekretnina_lokacija $nekretnina_povrsina ORDER BY nekretnina_id DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/241025-real-estate-search-engine-new-problem/#findComment-1238099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.