Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to correctly use >= in a query.
Old 08-16-2005, 06:15 PM How to correctly use >= in a query.
Experienced Talker

Posts: 36
Trades: 0
Hello all.

I have a search form which I'd like to return values based on values entered. Until now I had been returning results based on values equal to those entered. Basically if the values in the search form entered were:

Nationality:British
Sex:Male
Prefecture:Tokyo
Price:3000

All results returned from the search would be British males from Tokyo whose price is 3000.

However I wished to change the query so that results returned would include values less than or equal to the price entered.

My original query was as follows:
PHP Code:
$query_m "SELECT TestTable.autonumber, TestTable.sex, TestTable.firstname, TestTable.nationality, TestTable.private_price FROM TestTable WHERE TestTable.language LIKE '%" $_REQUEST["language"] . "%' AND TestTable.prefecture LIKE '%" $_REQUEST["prefecture"] . "%' AND TestTable.sex LIKE '%" $_REQUEST["sex"] . "%'AND TestTable.nationality LIKE '%" $_REQUEST["nationality"] . "%'  AND TestTable.mm LIKE '%" $_REQUEST["mm"] . "%'  AND TestTable.ma LIKE '%" $_REQUEST["ma"] . "%'  AND TestTable.me LIKE '%" $_REQUEST["me"] . "%'  AND TestTable.tm LIKE '%" $_REQUEST["tm"] . "%'  AND TestTable.ta LIKE '%" $_REQUEST["ta"] . "%'  AND TestTable.te LIKE '%" $_REQUEST["te"] . "%'  AND TestTable.wm LIKE '%" $_REQUEST["wm"] . "%'  AND TestTable.wa LIKE '%" $_REQUEST["wa"] . "%'  AND TestTable.we LIKE '%" $_REQUEST["we"] . "%'  AND TestTable.thm LIKE '%" $_REQUEST["thm"] . "%'  AND TestTable.tha LIKE '%" $_REQUEST["tha"] . "%'  AND TestTable.the LIKE '%" $_REQUEST["the"] . "%'  AND TestTable.fm LIKE '%" $_REQUEST["fm"] . "%'  AND TestTable.fa LIKE '%" $_REQUEST["fa"] . "%'  AND TestTable.fe LIKE '%" $_REQUEST["fe"] . "%'  AND TestTable.sm LIKE '%" $_REQUEST["sm"] . "%'  AND TestTable.sa LIKE '%" $_REQUEST["sa"] . "%'  AND TestTable.se LIKE '%" $_REQUEST["se"] . "%'  AND TestTable.sum LIKE '%" $_REQUEST["sum"] . "%'  AND TestTable.sua LIKE '%" $_REQUEST["sua"] . "%'  AND TestTable.sue LIKE '%" $_REQUEST["sue"] . "%' AND 
TestTable.private_price LIKE '%" 
$_REQUEST["private_price"] . "%'"
in particular note:
AND
PHP Code:
TestTable.private_price LIKE '%" . $_REQUEST["private_price"] . "%'"; 
This returned all values as expected.
However, I tried replacing this private price to include equal to or less than values, but had no success. I tried the following (in place of the above):

TestTable.private_price <= .'$_REQUEST["private_price"] . '

TestTable.private_price =< .'$_REQUEST["private_price"] . '

TestTable.private_price =< " . $_REQUEST["private_price"] . " ERROR (You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '=< 1000' at line 2)

TestTable.private_price <= '%" . $_REQUEST["private_price"] . "%'

TestTable.private_price <= $_REQUEST["private_price"]

These all returned errors....

Can anyone help???


Thanks for reading this guys
jool is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2005, 06:54 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Did you try:

" .... TestTable.private_price <= " . $_REQUEST["private_price"] . " .... "

(the dots just represent the rest of your query.)
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 08-17-2005, 07:42 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
What exact errors did they return?

Of course, one thing I would do (just to reduce the confusion of the code and assure yourself that none of the errors are resulting from the mis-handling of the $_REQUEST global) is to assign it to a local variable first then simply include it within the double quoted sql composition:

$privPrice = $_REQUEST[private_price];

$sql = "......... TestTable.private_price <= $privPrice";

Of course, the other issue here could be using the <= with a string -- that could cause some unexpected results unless you are absolutely certain of the homogeny of all the values in that column. I would suggest storing the price as a float and composing the sql without quotes around the $privPrice value.

HTH.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 08-17-2005, 09:35 AM
Experienced Talker

Posts: 36
Trades: 0
Thanks Oberon, Kyrnt (sorry for submitting twice - not sure what I was doing)

Oberon, as you suggested, I tried

TestTable.private_price <= " . $_REQUEST["private_price"] . "

and it worked!....I'm a bit stunned as I thought I'd tried all the variations.

Well thanks so much. Your response has resolved something I was getting concerned that I might never fix.
jool is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 09:36 AM
Experienced Talker

Posts: 36
Trades: 0
Thanks also Kyrnt - Your advice is much appreciated.
jool is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 09:42 AM
Experienced Talker

Posts: 36
Trades: 0
Quick observation - On returning to Dreamweaver I see that my recordset (m) associated with the above query(m) no longer appears in my bindings panel and a red exclamation mark appears nex to the (m) repeat region server behaviour in the server behaviour panel.

However, if the set-up works, I'm not too worried about this!
jool is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to correctly use >= in a query.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53046 seconds with 12 queries