Skip to main content
Inspiring
March 24, 2008
Question

un known query result

  • March 24, 2008
  • 1 reply
  • 255 views
I have one query which is running good and it is producing no error:

just this is the query:

<cfquery datasource="#request.dsn#" username="#request.user#" password="#request.password#" name="randommode">
Select DISTINCT(property_id), property_file, property_unique_name,
mode, price_range, status
FROM
properties_details
where properties_details.status = <cfqueryparam cfsqltype="cf_sql_numeric" value="1">
AND
properties_details.mode = <cfqueryparam cfsqltype="cf_sql_varchar" value="Rental">
OR
properties_details.mode = <cfqueryparam cfsqltype="cf_sql_varchar" value="Sale">
ORDER BY rand()
limit 3
</cfquery>

i am getting results where the status is 1 and if mode is 2, then property will not show up but for unknown reason it is not procduing any error and it is returning all the properties wheather the status is 1 or 2

if i removce the following options of "rental" and "sale" then this query runs good but if i attach them it returns all results whose status is 1 or 2
    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    March 24, 2008
    if mode is 2

    Confusion. Here mode is an integer, in your code it is a varchar. Assuming that mode is indeed the varchar 'Rental' or 'Sale', then you could introduce brackets in the last two where-clauses, thus

    WHERE properties_details.status = <cfqueryparam cfsqltype="cf_sql_numeric" value="1">
    AND
    (properties_details.mode = <cfqueryparam cfsqltype="cf_sql_varchar" value="Rental">
    OR
    properties_details.mode = <cfqueryparam cfsqltype="cf_sql_varchar" value="Sale">)