#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    7
    Rep Power
    0

    CFIF to show based on first two letters of ID


    I am trying to figure out how to get a CFIF statement to display a graphic for each product that has a product ID that starts with the letters "PL". I am using a MySQL database and CFMX remote server.

    For example, I want all products that have an ID that begins with the letters "PL" to show a graphic that says, "Special: 25% off".

    Thanks in advance for any assistance.
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    If your database query returns something like "getProducts.productID", then you can simply do:

    <cfif left( getProducts.productID, '2' ) eq 'PL'>
    <img src="path to 25% off image">
    </cfif>
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    7
    Rep Power
    0
    Thanks. That worked.

    What if I want to select only items starting with "PL" from the database and display only those items? I tried using the above code (modified) to accomplish this, but I keep getting an error in my syntax.

    Here's where I pull from the database only products that are "designated" to show on the web site:

    <cfquery name="getProduct" datasource="datasource" username="username" password="password">

    SELECT * FROM Products WHERE (OnWeb = 'Yes')
    <cfif IsDefined ('Cat')>

    I tried using the "<cfif left( getProducts.productID, '2' ) eq 'PL'> but haven't had any luck.

    Any suggestions?

    Thanks in advance.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    In your SQL you wouldn't use the CFML left() function, but your RDBMS should have a similar function. That's what you want to use in your where clause. Just to be clear, you can use CFML to *construct* the SQL statement, but once you send it to the database, you must rely on *database* functions to determine which records to return. Most databases have a full set of functions available.

IMN logo majestic logo threadwatch logo seochat tools logo