Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql retrieve data based on select -option tag
    primarykey
    data
    text
    <p>I'm trying to make a real estate website and I have some difficulties with the search form.</p> <p>The form has 5 fields: price_from; price_to; number_rooms, location and numb_square_meters. The data base has 5 columns: id, price, location, numb_square_meters, number_rooms.</p> <p>For the price fields I use an input type field. For numb_rooms I use a select type field with options like(vila, condo, 4 bedroom apartments..something like that and ALL OPTIONS option). For location and square_meters is the same way as for numb_rooms.</p> <p>The problem is this actually there are more than one:</p> <ol> <li><p>When I choose the option "ALL OPTIONS" in the LOCATION field in my form I want it to retrieve every location from the SQL DB if not to retrieve one of the other options</p></li> <li><p>If lets say the user fills the price fields but the other ones remain with the ALL OPTIONS option selected, I want it to retrieve only the rows that is in that price range no matter the location number of rooms or the square meters</p></li> </ol> <p>This a part of my code...</p> <pre><code> &lt;form method="post" action="index.php" enctype="multipart/form-data"&gt; &lt;input type="hidden" name="id"&gt; Price &lt;input type="text" name="price"&gt; Price2 &lt;input type="text" name="price2" /&gt; Square_meters&lt;input type="text" name="Square_meters"&gt; Location&lt;select name="Location"&gt; &lt;option&gt;All options&lt;/option&gt; &lt;option&gt;Bucuresti&lt;/option&gt; &lt;option&gt;Iasi&lt;/option&gt; &lt;option&gt;Brasov&lt;/option&gt; &lt;option&gt;Focsani&lt;/option&gt; &lt;/select&gt; Numb_rooms&lt;select name="Numb_rooms"&gt; &lt;option&gt;All options&lt;/option&gt; &lt;option&gt;Garsoniera&lt;/option&gt; &lt;option&gt;2 Camere&lt;/option&gt; &lt;option&gt;3 Camere&lt;/option&gt; &lt;option&gt;4 Camere&lt;/option&gt; &lt;option&gt;Vila&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" name="send" value="Search"&gt; &lt;/form&gt; &lt;?php header("content-type: image.jpg"); if(isset($_POST['send'])) { require_once("conexiune.php"); (this is my conect to sql database script) $id = $_POST['id']; $price = $_POST['price']; $price2 = $_POST['price2']; $square_m = $_POST['Square_meters']; $location = $_POST['location']; $numb_rooms = $_POST['Numb_rooms']; $selectie = mysql_query("SELECT * FROM apartamente WHERE id = '$id' &amp;&amp; Pret&gt;='$price'&amp;&amp; Pret&lt;='$price2' &amp;&amp; Location = '$location' &amp;&amp; Square_meters='$Square_meters' &amp;&amp; Numb_rooms = '$Numb_rooms ' "); while($row = mysql_fetch_array($selectie,MYSQL_ASSOC)) { print"&lt;tr&gt;&lt;td&gt;"; print $row['id']; print"&lt;/td&gt;&lt;td&gt;"; print $row['Pret']; print"&lt;/td&gt;&lt;td&gt;"; print $row['Nr_camere']; print"&lt;/td&gt;&lt;td&gt;"; print $row['Suprafata']; print"&lt;/td&gt;&lt;td&gt;"; print $row['Locatie']; print"&lt;/td&gt;&lt;td&gt;"; print $row['Descriere']; print"&lt;/td&gt;&lt;td&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload