Jump to content


Photo

Price Range form question??????


  • Please log in to reply
6 replies to this topic

#1 SixtyNine

SixtyNine
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 June 2006 - 06:29 AM

Hi PHP Freaks,
Im new to this forum.
I need a helpful kind soul to help me out here ;)

I have tryed for a week now figuring out how to drag a price range
out of my database. I have looked everywhere on the
net for answers to my problem without any luck.
This is driving be BaNaNazzzzzzz.

I have tryed this:
WHERE Sheet1.PriceCAN >= '$LowPrice' AND Sheet1.PriceCAN =< '$HighPrice'")
do not seem to work.


WHERE Sheet1.PriceCAN BETWEEN '$LowPrice' AND '$HighPrice'")

I tryed this:
WHERE Sheet1.PriceCAN BETWEEN 200 AND 700")
This will work but need to be the values from my HTML form.


WHAT DO I DO WRONG ????, i feel i have tryed everything.


I have a HTML form who looks like this

<html>
<head></head>
<body>
<form action="search_db.php" method="post">
<SELECT name="PriceLow">
<option value="200">$200
<option value="500">$500
<option value="1000">$1000
<option value="500">$1500
<option value="1000">$2000
</SELECT>

<SELECT name="PriceHigh">
<option value="500">$500
<option value="1000">$1000
<option value="2000">$2000
<option value="500">$2500
<option value="1000">$3000
</SELECT>

<input type="submit" value="Search">
</form>
</body>
</html>



My page: search_db.php looks like this:


mysql_connect($hostname,$username, $password);
mysql_select_db($dbname);


$LowPrice = $_POST['LowPrice'];
$HighPrice = $_POST['HighPrice'];


$result = mysql_query("SELECT StockNumber, Shape, Size, Colour, Clarity, Make, CertType, MaxDim, MinDim, DepthDim, PriceCAN, Sheet1.PriceCAN*1.3 AS FIELD_1 FROM Sheet1 WHERE Sheet1.PriceCAN BETWEEN '$LowPrice' AND '$HighPrice'")
or die(mysql_error());


echo "<center><table bgcolor='#E2EBEE' style='border: 2px solid gray; padding: 1em; border-spacing: 1pt ' border='1'>";
echo "<tr> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Stock Number</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Shape</td><td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Size</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Colour</td><td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Clarity</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Make</td><td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Cert Type</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Maximum Dimention</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Minimum Dimention</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Depth Dimention</td> <td bgcolor='#7BA1AC' style='border-style: solid; font-weight: bolder; font-size: 10px; font-family: Verdana' >Price CAN$</td></tr>";

while($row = mysql_fetch_array( $result )) {

echo "<tr><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['StockNumber'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['Shape'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['Size'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['Colour'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['Clarity'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['Make'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['CertType'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['MaxDim'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['MinDim'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['DepthDim'];
echo "</td><td bgcolor='#F8FBFC' style='border-style: solid; font-size: 12px; font-family: Verdana'>";
echo $row['PriceCAN'];
echo "</td></tr>";
}
echo "</table></center>";

?>





#2 azuka

azuka
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 13 June 2006 - 08:19 AM

I've noticed some inconsistencies in your code.
  • Your form select names are 'PriceLow' an 'PriceHigh' yet you call $_POST['LowPrice'] and $_POST['HighPrice']
  • so if you changed
    $LowPrice = $_POST['LowPrice']; 
     $HighPrice = $_POST['HighPrice'];
    to
    $LowPrice = $_POST['PriceLow']; 
     $HighPrice = $_POST['PriceHigh'];
    your code should work well.
After that, you might consider removing illegal characters from $_POST so that you don't get any SQL injection attacks.

Just try making the suggested modifications and see if they work.

Given enough eyeballs all bugs are shallow. My Website

#3 SixtyNine

SixtyNine
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 June 2006 - 12:38 PM

Thank you for quik reply,

This forum rules.

Azuka you Rock [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Right on.

Do I ever feel stupid now.
Thanx a million.

"SixtyNine"

#4 SixtyNine

SixtyNine
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 June 2006 - 07:52 AM

I got another thing here that i'm trying to figure out how to go about.??????

I need to mark up PriceCAN, but if done the way below i end up with my price range
marked up, so that it will not be in the price range searched on, if you get my drift.

while($row = mysql_fetch_array( $result)) {
$PriceCAN = $row['PriceCAN'];

if ($PriceCAN >= 1 and $PriceCAN <= 500){
$row['PriceCAN'] = $PriceCAN*4.4;
}

if ($PriceCAN >= 500 and $PriceCAN <= 700){
$row['PriceCAN'] = $PriceCAN*3.9;
}

and so on......

Could it be done with dividing first and then multiplying after the data is fetched?

if ($LowPrice >= 1 and $HighPrice <= 500){
$LowPrice = $LowPrice / 4.4;
$HighPrice = $HighPrice / 4.4;


}

and so on....
Don't know if i'm going about this the right way ???????

Thanx for a great forum. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 June 2006 - 01:34 PM

I guess you could also do this on the MySQL side as well, so you don't have to worry about the go-between stages.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 SixtyNine

SixtyNine
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 June 2006 - 02:20 PM

Thanks for replying.

So run a UPDATE query in MySQL with the markup calculation ?
Is that what you mean?

Then keep a backup copy of the database, so that if i wanna change my markup
calculations i run a update query again on the original database file?

Am i understanding this correctly ?

[img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]



#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 June 2006 - 05:09 AM

[!--quoteo(post=386024:date=Jun 20 2006, 10:20 AM:name=SixtyNine)--][div class=\'quotetop\']QUOTE(SixtyNine @ Jun 20 2006, 10:20 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thanks for replying.

So run a UPDATE query in MySQL with the markup calculation ?
Is that what you mean?

Then keep a backup copy of the database, so that if i wanna change my markup
calculations i run a update query again on the original database file?

Am i understanding this correctly ?

[img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
[/quote]
No... I mean that giving the "proper" price range, you can use column aliases & expressions to produce whatever values to want.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users