I have a table of kids(5) and which of the 6 fruits they bring:
Table: KidsData
ID Name FruitData
1 Candy 100000
2 Andy 001000
3 Sarah 001010
4 Gabby NULL
5 Jack 000110
Table: Fruitdescription
ID FruitName
1 apple
2 orange
3 kiwi
4 banana
5 pineapple
6 grape
<cfquery name="kidsData">
SELECT *
FROM KidsData
WHERE FruitData IS NOT NULL AND ID = #ID#
</cfquery>
<cfoutput query="kidsData">
<cfif #left(#FruitData#, 1)# EQ '1'>
Apple
</cfif>
<cfif #left(#FruitData#, 2)# EQ '1'>
Orange
</cfif>
<cfif #left(#FruitData#, 3)# EQ '1'>
Kiwi
</cfif>
<cfif #left(#FruitData#, 4)# EQ '1'>
Banana
</cfif>
<cfif #left(#FruitData#, 5)# EQ '1'>
Pineapple
</cfif>
<cfif #left(#FruitData#, 6)# EQ '1'>
Grape
</cfif>: #Name#<br />
</cfoutput>
The code works fine if there is only 1 fruit in #FruitData# string, like
Apple: Candy
Kiwi: Andy
But for the #FruitData# string that has multiple 1s only shows the first record that it hits for 1, like
Kiwi: Sarah
Banana: Jack
it is not showing the output as needed:
Kiwi: Sarah
Pineapple: Sarah
Banana: Jack
Pineapple: Jack
I don't know where I'm wrong. Any help is appreciated.
Table: KidsData
ID Name FruitData
1 Candy 100000
2 Andy 001000
3 Sarah 001010
4 Gabby NULL
5 Jack 000110
Table: Fruitdescription
ID FruitName
1 apple
2 orange
3 kiwi
4 banana
5 pineapple
6 grape
<cfquery name="kidsData">
SELECT *
FROM KidsData
WHERE FruitData IS NOT NULL AND ID = #ID#
</cfquery>
<cfoutput query="kidsData">
<cfif #left(#FruitData#, 1)# EQ '1'>
Apple
</cfif>
<cfif #left(#FruitData#, 2)# EQ '1'>
Orange
</cfif>
<cfif #left(#FruitData#, 3)# EQ '1'>
Kiwi
</cfif>
<cfif #left(#FruitData#, 4)# EQ '1'>
Banana
</cfif>
<cfif #left(#FruitData#, 5)# EQ '1'>
Pineapple
</cfif>
<cfif #left(#FruitData#, 6)# EQ '1'>
Grape
</cfif>: #Name#<br />
</cfoutput>
The code works fine if there is only 1 fruit in #FruitData# string, like
Apple: Candy
Kiwi: Andy
But for the #FruitData# string that has multiple 1s only shows the first record that it hits for 1, like
Kiwi: Sarah
Banana: Jack
it is not showing the output as needed:
Kiwi: Sarah
Pineapple: Sarah
Banana: Jack
Pineapple: Jack
I don't know where I'm wrong. Any help is appreciated.