carlitoway Posted September 9, 2013 Share Posted September 9, 2013 Hello guys, Im new in php and im trying to creat a multi inputs search... here is my problem I want to search on three inputs select (tipo,ciudad and precio) searching on the web i have this code, but it doesnt work, just show me "Not results" so here is my code, any help will be appreciated <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'> <p>Tipo</p> <select name="opt1"> <option value="" selected>all</option> <option value="nave">Naves</option> <option value="penthouse">Penthouse</option> <option value="residencia">Residencias</option> <option value="villa">Villas</option> </select> <p>Ciudad</p> <select name="opt2"> <option value="santo domingo">Santo Domingo</option> <option value="samana">Samana</option> </select> <p>Precios</p> <select name="opt3"> <option value="terrenas">terrenas</option> </select> <input type='submit'> </form> <?php include ("conexion.php"); $opt1 = $_POST['opt1']; $opt2 = $_POST['opt2']; $opt3 = $_POST['opt3']; $result = mysql_query("SELECT * FROM `inmuebles` WHERE `tipo` = '".$opt1."' AND `ciudad` = '".$opt2."' AND `sector` = '".$opt3."'"); if ($row = mysql_fetch_array($result)){ echo " <table> <tr> <td>" .$row["tipo"]. "</td> <td>" .$row["ciudad"]. "</td> <td>" .$row["sector"]. "</td> </tr> </table> "; } else { echo "<div class='container' style='text-align:center;'>No disponible</div>"; } ?> </div> Any help will be appreciated Quote Link to comment Share on other sites More sharing options...
Barand Posted September 9, 2013 Share Posted September 9, 2013 If the "all" option for Tipo is selected you need to leave it out of the query otherwise you are looking for tipo='' instead of all values Quote Link to comment Share on other sites More sharing options...
carlitoway Posted September 9, 2013 Author Share Posted September 9, 2013 Thank you Barad... my code was wrong in the select SQL Now its works but just show me one record and the same code on my PhpmyAdmin works perfectly and show me all the Records, and now i dont know what im doing wrong.... this is what i have change and I also did what you said.. Thank you very much bro! $result = mysql_query(" SELECT * FROM `inmuebles` WHERE tipo = '".$opt1."' OR ciudad = '".$opt2."' OR sector = '".$opt3."' "); Quote Link to comment Share on other sites More sharing options...
DavidAM Posted September 9, 2013 Share Posted September 9, 2013 if ($row = mysql_fetch_array($result)){ echo " <table> <tr> <td>" .$row["tipo"]. "</td> <td>" .$row["ciudad"]. "</td> <td>" .$row["sector"]. "</td> </tr> </table> "; } You are only fetching and echo'ing ONE row, so that is all you see. You will need to loop through the returned rows: if (mysql_num_rows($result)) { echo "<TABLE>"; while ($row = mysql_fetch_array($result)) { echo " <tr> <td>" .$row["tipo"]. "</td> <td>" .$row["ciudad"]. "</td> <td>" .$row["sector"]. "</td> </tr>"; } echo "</TABLE>"; } Quote Link to comment Share on other sites More sharing options...
carlitoway Posted September 9, 2013 Author Share Posted September 9, 2013 WOW THIS REALLY WORKS NOW!!!! MANY MANY THANKS GUYS I DO APPRECIATE YOUR HELP! and now I will leave the entre code to all those guys who will search for the same thing! this is really important and all thanks to you guyz DavidAM and Barand and Filecipher& Adrian Hendrich from google+ <div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='POST'> <p>Tipo</p> <select name="opt1"> <option selected>all</option> <option value="apartamentos">Apartamentos</option> <option value="nave">Naves</option> <option value="penthouse">Penthouse</option> <option value="residencia">Residencias</option> <option value="villa">Villas</option> </select> <p>Ciudad</p> <select name="opt2"> <option selected>all</option> <option value="santo domingo">Santo Domingo</option> <option value="santiago">Santiago</option> <option value="samana">Samana</option> <option value="punta cana">punta cana</option> </select> <p>Precios</p> <select name="opt3"> <option selected>all</option> <option value="terrenas">terrenas</option> <option value="bavaro">bavaro</option> <option value="naco">naco</option> </select> <input type='submit'> </form> <?php include ("conexion.php"); $opt1 = $_POST['opt1']; $opt2 = $_POST['opt2']; $opt3 = $_POST['opt3']; $result = mysql_query(" SELECT * FROM `inmuebles` WHERE tipo = '".$opt1."' OR ciudad = '".$opt2."' OR sector = '".$opt3."' "); if (mysql_num_rows($result)) { echo "<TABLE>"; while ($row = mysql_fetch_array($result)) { echo " <tr> <td>" .$row["tipo"]. "</td> <td>" .$row["ciudad"]. "</td> <td>" .$row["sector"]. "</td> </tr>"; } echo "</TABLE>"; } ?> </div> thank you very much for your help guyz! God bless you all Quote Link to comment 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.