|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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> |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > CFIF to show based on first two letters of ID |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|