Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why wont this work right

Status
Not open for further replies.

pugs421

Technical User
Joined
Nov 25, 2002
Messages
114
Location
US
I had this working a different way but I'm trying to do it an easier way

if ($beds_result == 0)
{
$math_operator = '>=';
}
if ($beds_result > 0)
{
$math_operator = '=';
}

$query_Rslistings = "SELECT * FROM listings WHERE city = '$city_result' AND beds '$math_operator' '$beds_result' AND price BETWEEN '$min_price_result' AND '$max_price_result'";

I just want the one of the math operators entered into the query depending on what the user enters.I't worked a different way so I know It's only a syntax problem. Any ideas?


Check the manual that corresponds to your MySQL server version for the right syntax to use near ">=' '0'
 
i dont think there is a workaround cause the situations are different... does this curren sql throw any error?

Known is handfull, Unknown is worldfull
 
You need not quote your math operator. It is not a string value (from the SQL's point of view) but part of the SQL syntax:
Code:
"SELECT * FROM listings WHERE city = '$city_result' AND beds $math_operator '$beds_result' AND price BETWEEN '$min_price_result' AND '$max_price_result'";

I just removed the quotes aroung $math_operator.
With quotes it is syntactically wrong.
 
[rofl2]

Known is handfull, Unknown is worldfull
 
Thanks. Quotes were the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top