Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP IN CFIF STATEMENT - PLEASE HELP !!!

Status
Not open for further replies.

kingjjx

Programmer
Joined
Sep 18, 2001
Messages
181
Location
US
Hi, I have a table field that may contain upto 5 codes separated by commas (1,2,3,4,5)

I want to output Image 1 If code 1 is found, output Image 2 if COde 2 is found, output image 3 if code 3 is found and so fourth ...
BUT I want it to output 3 images if 3 codes are found, 1 image if only one code is present.

I am close to doing this already but, the problem with my code is if the code found is (1,2,3) it only outputs image 1.

Please help !!!!
thanks

 
i'll take it that in the query you are using IN keyword to get all the 'codes', e.g.:

...WHERE fieldname IN (1,2,3,4,5)...

check to make sure that the recordcount of the executed query is 3 when you should have 3 possible matches;

if the code found is (1,2,3), now you have to loop through the query or to output all the results:

<cfloop query=&quot;queryname&quot;>
<output><img src=&quot;images/#fieldname#&quot;><br></output>
</cfloop>

Sylvano
dsylvano@hotmail.com
 
Can you post your code? You can do a listfind to see if the code is there:

<cfquery name=&quot;foo&quot; datsource=&quot;bar&quot;>
Select code from my table
</cfquery>

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(foo.code,&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(foo.code,&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

etc...
</cfquery>

Or another way would be to use a loop.

eg.

<cfloop from=&quot;1&quot; to &quot;5&quot; index=&quot;idx&quot;>
<cfif ListFind(foo.code, idx)>
<cfoutput><img src=&quot;Image#idx#.gif&quot;></cfoutput>
</cfif>


(if your images were called Image1.gif, Image2.gif, etc.)
 
Hi CfDude, My code looks exactly like what u just posted:

<cfquery name=&quot;foo&quot; datsource=&quot;bar&quot;>
Select code from my table
</cfquery>

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(foo.code,&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(foo.code,&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

The problem with this is that if it finds a &quot;1&quot; then it just outputs image 1, even if the codes are(1,2,3) it seems to just look at the first code it finds.

What I want is to check for whatever code is available and output all the images associated with the codes. So if its 1,2,5 it should output images 1,2 and 5.

thanks - please help
 
I don't know why it is not working for you. I just tested it on my machine and it worked fine. I put the incorrect image name in my cfif -- it should have been:

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(foo.code,&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(foo.code,&quot;2&quot;)>
<img src=&quot;image2.gif&quot;>
</cfif>

I had &quot;image1&quot; listed twice -- is that the cause?

If not, try just outputting the code field and make sure that it in fact does have the numbers in there.

If all else fails, post your code, I might be missing something.
 
foo.code in the ListFind is checking for the first record only; chanhe to this and it will work:

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(code,&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(code,&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

or:

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(foo.code[CurrentRow],&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(foo.code[CurrentRow],&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

or:

<cfoutput query=&quot;foo&quot;>
<img src=&quot;image#code#.gif&quot;>


Sylvano
dsylvano@hotmail.com
 
Hi, WWebspider, I tried your code and its still only returning the image for the first code it sees.

I tried:
cfoutput query=&quot;foo&quot;>
<cfif ListFind(code,&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(code,&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

AND

<cfoutput query=&quot;foo&quot;>
<cfif ListFind(foo.code[CurrentRow],&quot;1&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>
<cfif ListFind(foo.code[CurrentRow],&quot;2&quot;)>
<img src=&quot;image1.gif&quot;>
</cfif>

STILL ONY RETURNS THE IMAGE OF THE FIRST CODE IT SEES.
PLEASE HELP.
THANKS
 
plese run this and post the output:

<cfoutput query=&quot;foo&quot;>
#code#<br>
</cfoutput>
Sylvano
dsylvano@hotmail.com
 
FYI, we have duplicate threads going on. I'm currently posting my suggestions in thread232-279463 .

I believe the problem has to do with trailing white space being included in the list, so that a query that returned codes 1 and 5 is actually returning '1,5 ' which would make a ListFind(listname,&quot;5&quot;) return 0.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top