Jump to content

Search by min. and max price


ivalea

Recommended Posts

Hi!

I am trying to build a search form (am still pretty new to PHP and MySQL so please bear with me) that searches by min and max price by dropdown - like on a real estate site. Right now it's written so that if there are any listings in the database then it takes those prices and puts them in the dropdown. Otherwise if there are no listings then the dropdown shows no options. My code is this:

$MinPrice = "<select name=min>\n\t<option value=\"\">Minimum</option>\n\t";

$q1 = "select distinct Price from re2_listings order by Price asc";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
while($a1 = mysql_fetch_array($r1))
{
$prices .= "<option value=\"$a1[Price]\">$ $a1[Price]</option>\n\t";
}
}

$MinPrice .= $prices."</select>\n";


//set the max price menu
$MaxPrice = "<select name=max>\n\t<option value=\"\">Maximum</option>\n\t";
$MaxPrice .= $prices."</select>\n";


Then all I do is reference <?=$MinPrice?> and <?=$MaxPrice?> in the html form where the select should be.

I need the dropdown to display price values in increments of $50,000 starting at $150,000 and ending at $1,000,000+.

I tried inserting a select field in the form the way it normally would be and then setting id's to MinPrice and MaxPrice but that didn't work.

Sorry to be soooo long winded but I've been at this for what seems forever and I so need help! :)
Any thoughts at all as to how I can accomplish this would be sooo greatly appreciated!

Thanks! - Irene
Link to comment
Share on other sites




An example of the way i done the select box thats all good luck.

1 to 1099 pound

In drop down box
[code]
$a=$_POST['a']; // box1
$b=$_POST['b'];// box2
$c=$_POST['c'];//box3
$d=$_POST['d'];//box4
$price=('£'.$a.'.'.$b.$c);
[/code]

[code]
<td>Price</td>
<td>
<SELECT NAME="a">
<OPTION VALUE="0">0</option>
<OPTION VALUE="1">£1</option>
<OPTION VALUE="2">£2</option>
<OPTION VALUE="3">£3</option>
<OPTION VALUE="4">£4</option>
<OPTION VALUE="5">£5</option>
<OPTION VALUE="6">£6</option>
<OPTION VALUE="7">£7</option>
<OPTION VALUE="8">£8</option>
<OPTION VALUE="9">£9</option>
<OPTION VALUE="10">£10</option>
<OPTION VALUE="20">£20</option>
<OPTION VALUE="30">£30</option>
<OPTION VALUE="40">£40</option>
<OPTION VALUE="50">£50</option>
<OPTION VALUE="60">£60</option>
<OPTION VALUE="70">£70</option>
<OPTION VALUE="80">£80</option>
<OPTION VALUE="90">£90</option>
<OPTION VALUE="100">£100</option>
<OPTION VALUE="200">£200</option>
<OPTION VALUE="300">£300</option>
<OPTION VALUE="400">£400</option>
<OPTION VALUE="500">£500</option>
<OPTION VALUE="600">£600</option>
<OPTION VALUE="700">£700</option>
<OPTION VALUE="800">£800</option>
<OPTION VALUE="900">£900</option>
<OPTION VALUE="1000">£1000</option>



</SELECT>
<SELECT NAME="b">
<OPTION VALUE="0">0</option>
<OPTION VALUE="1">1</option>
<OPTION VALUE="2">2</option>
<OPTION VALUE="3">3</option>
<OPTION VALUE="4">4</option>
<OPTION VALUE="5">5</option>
<OPTION VALUE="6">6</option>
<OPTION VALUE="7">7</option>
<OPTION VALUE="8">8</option>
<OPTION VALUE="9">9</option>
<OPTION VALUE="10">10</option>
</SELECT>

<SELECT NAME="c">
<OPTION VALUE="0">0</option>
<OPTION VALUE="1">1</option>
<OPTION VALUE="2">2</option>
<OPTION VALUE="3">3</option>
<OPTION VALUE="4">4</option>
<OPTION VALUE="5">5</option>
<OPTION VALUE="6">6</option>
<OPTION VALUE="7">7</option>
<OPTION VALUE="8">8</option>
<OPTION VALUE="9">9</option>
<OPTION VALUE="10">10</option>
</SELECT>


[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.