PHP help

  RicScott 18:30 24 Apr 2006
Locked

I'm pretty new to php5..
I'm trying to design a form type SELECT> search from a mysql database.
Basically I've got 3 Selectors, Area, Price and Numbers.. I want to combine all 3 to narrow down the search.
I've put an HTML version online on a testing server..
The desired result would be to display not only was chosen from the select menu, but also 2 other columns from the db.
Anyone got a code so I can at least get a test version up and running. I'm running wamp on a test machine.

The idea is here:: click here

Any help would be appreciated. Thanks in advance.

  harristweed 09:13 25 Apr 2006

Have a look at...

click here

It has a similar search.

Here is some of the code from the search results page. It should point you in the right direction.

<?php

$type=$_GET[type];
$price_range=$_GET[price];
$beds=$_GET[beds];
//if a plot no beds
if($type=="1" and $beds > 0)
{
$beds="0";
}

// link to data
$link_id = mysql_connect("$db_host","$db_user","$db_password");
if (mysql_select_db("$db_database", $link_id));
else die ("connection failed.") ;
$flag = 0;
$query_search="";
$message="You requested ";
if($type=="0")$message.= "any type of property ";
if($type !=="0")// if search is NOT for all a bit more needs to be added
{
if($type=="1")
{
$prop_type="Plot";
$message.="a plot ";
}
if($type=="2")
{
$prop_type="Apartment";
$message.="an apartment ";
}
if($type=="3")
{
$prop_type="Villa";
$message.="a villa ";
}
$query_search.= " WHERE prop_type = '$prop_type' ";
// now set a flag so we know that a WHERE has been addeed
$flag = 1;
}

if($price !=="0")//same again for price
{
if($price_range=="1")
{
$range=" < 100000 ";
$message.="priced less than 100,000 € ";
}
if($price_range=="2")
{
$range=" between 100000 and 200000";
$message.="priced between 100,000 € and 200,000 € ";
}
if($price_range=="3")
{
$range=" between 200000 and 300000";
$message.="priced between 200,000 € and 300,000 € ";
}
if($price_range=="4")
{
$range=" between 300000 and 400000";
$message.="priced between 300,000 € and 400,000 € ";
}
if($price_range=="5")
{
$range=" between 400000 and 500000";
$message.="priced between 400,000 € and 500,000 € ";
}
if($price_range=="6")
{
$range=" between 500000 and 600000";
$message.="priced between 500,000 € and 600,000 € ";
}
if($price_range=="7")
{
$range=" between 600000 and 700000";
$message.="priced between 600,000 € and 700,000 € ";
}
if($price_range=="8")
{
$range=" between 700000 and 800000";
$message.="priced between 700,000 € and 800,000 € ";
}
if($price_range=="9")
{
$range=" between 800000 and 900000";
$message.="priced between 800,000 € and 900,000 € ";
}
if($price_range=="10")
{
$range=" between 900000 and 1000000";
$message.="priced between 900,000 € and 1,000,000 € ";
}
if($price_range=="11")
{
$range=" > 1000000";
$message.="priced over 1,000,000 € ";
}
if($flag ==1)// we already added the WHERE
{
$query_search.= " AND price $range ";
}else{
// if this bit is actioned we need to add WHERE and set the flag
$query_search.= " WHERE price $range ";
$flag = 1;
}
}
if($beds !=="0")//same again for pattern
{
$message.="with at least $beds bedrooms ";
if($flag ==1)// we already added the WHERE
{
$query_search.= " AND beds >= $beds ";
}else{
$query_search.= " WHERE beds >= $beds ";
// as this is last dont need flag
}
}
// now add the last bit
$select="SELECT prop_id, ref, price, location, sold, prop_type FROM property_sale $query_search ORDER BY price ASC ";
$results = mysql_query("$select", $link_id);
$total_results = mysql_num_rows($results);

..........................

Hope this helps.

  RicScott 10:39 25 Apr 2006

Many thanks for that..Will have a play with it..
The original one I did is in Flash...
click here

Getting a bit too big now lol..

Thanks again..

Ric

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Alienware 17 R4 2017 review

These brilliant Lego posters show just what children's imaginations are capable of

Mac power user tips and hidden tricks

Comment réinitialiser votre PC, ordinateur portable ou tablette Windows ?