SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: CF Filtering

  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    0 Post(s)
    0 Thread(s)

    CF Filtering

    Good morning
    I need to know how I can exclude certain rows if a criteria is not specified.
    I am developing a property management website. On this website are 1, 2 & 3 bedroom apartment listings. When a person goes on to the site, they will choose how many bedrooms they are looking for.
    When they press the submit button, they will be taken to the appropriate page where all the available bedrooms will show. The only problem with this page is that it shows “all” of the bedrooms, including the ones that are “unavailable”. Is there any way to not show an apartment if it is designated in my database as ”unavailable” ?

    Below is the code I inputted on the top of my action page:

    <cfquery name="Apt_Results" datasource="BD_Foproperties">
    SELECT FOUnitDescription.Location, FOUnitDescription.PropertyName, FOUnitDescription.Available, FOUnitDescription.Amenity, FOUnitDescription.Address, FOUnitDescription.UnitNumber, FOUnitDescription.Bedroom, FOUnitDescription.Bathroom, FOUnitDescription.SquareFootage, FOUnitDescription.Rent
    FROM FOUnitDescription
    WHERE 0=0
    AND bedroom
    AND bathroom
    AND Available<>’unavailable’

    <!--- If Query Begin--->
    <cfif bedroom IS NOT "">
    AND Bedroom LIKE '%#bedroom#%'
    <cfif bathroom IS NOT "">
    AND Bathroom LIKE '%#bathroom#%'
    <!---If Query End--->
    ORDER BY FOUnitDescription.SquareFootage DESC, Rent DESC

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    Quote Originally Posted by designitbalhas View Post
    Is there any way to not show an apartment if it is designated in my database as ”unavailable” ?
    sure, just add a WHERE condition, something like

    ... AND Available <> 'unavailable'

    your columns are very weird, what datatype are they?

    they look like booleans here --

    WHERE 0=0
    AND bedroom
    AND bathroom

    but they look like character strings here --

    AND Bedroom LIKE '%#bedroom#%'

    AND Bathroom LIKE '%#bathroom#%'

    what's going on? | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts