Jump to content

Archived

This topic is now archived and is closed to further replies.

SixtyNine

Price Range form question??????

Recommended Posts

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>";

?>



Share this post


Link to post
Share on other sites
I've noticed some inconsistencies in your code.
[list][*]Your form select names are 'PriceLow' an 'PriceHigh' yet you call $_POST['LowPrice'] and $_POST['HighPrice'][*]so if you changed
[code] $LowPrice = $_POST['LowPrice'];
$HighPrice = $_POST['HighPrice'];[/code] to [code] $LowPrice = $_POST['PriceLow'];
$HighPrice = $_POST['PriceHigh'];[/code] your code should work well.[/list]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.

Share this post


Link to post
Share on other sites
Thank you for quik reply,

[u]This forum rules.[/u]

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"

Share this post


Link to post
Share on other sites
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\" /]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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\" /]

Share this post


Link to post
Share on other sites
[!--quoteo(post=386024:date=Jun 20 2006, 10:20 AM:name=SixtyNine)--][div class=\'quotetop\']QUOTE(SixtyNine @ Jun 20 2006, 10:20 AM) [snapback]386024[/snapback][/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.

Share this post


Link to post
Share on other sites

×

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.