November 9th, 2003, 09:20 AM
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.
November 10th, 2003, 11:22 AM
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">
November 20th, 2003, 12:28 PM
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.
Thanks in advance.
November 20th, 2003, 12:41 PM
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.