Hi guys my name is Chris i'm on this forum and in php programming so i have a few questions, i hope somebody can help me.
So:
i' m trying to make a real estate website and i have some difficulties with the search form
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
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 apartaments..something like that and ALL OPTIONS option)
For location and square_meters is the same way as for numb_rooms
The problem is this actually there are more than one:
1.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
2. If let say the user fills the price fields but the other ones remain with the ALL OPTIONS option selected i want it to retreive only the rows that is in that price range no matter the location number of rooms or the square meters
i want to point out the english is not my maternal language , so if you spot some spelling or grammar errors i apologize.
This a part of my code...
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="hidden" name="id">
Price <input type="text" name="price">
Price2 <input type="text" name="price2" />
Square_meters<input type="text" name="Square_meters">
Location<select name="Location">
<option>Bucuresti</option>
<option>Iasi</option>
<option>Brasov</option>
<option>Focsani</option>
</select>
Numb_rooms<select name="Numb_rooms">
<option>Garsoniera</option>
<option>2 Camere</option>
<option>3 Camere</option>
<option>4 Camere</option>
<option>Vila</option>
</select>
<input type="submit" name="send" value="Search">
</form>
<?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' && Pret>='$price'&& Pret<='$price2' && Location = '$location' && Square_meters='$Square_meters' && Numb_rooms = '$Numb_rooms ' ");
while($row = mysql_fetch_array($selectie,MYSQL_ASSOC))
{
print"<tr><td>";
print $row['id'];
print"</td><td>";
print $row['Pret'];
print"</td><td>";
print $row['Nr_camere'];
print"</td><td>";
print $row['Suprafata'];
print"</td><td>";
print $row['Locatie'];
print"</td><td>";
print $row['Descriere'];
print"</td><td>";