Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Loop Through Two Lists?

I need to join the output of two separate lists together to output in a CFMAIL, and I'm wondering what the best way to approach this is.

I have two form fields: first_name and last_name

The fields have up to 5 names in each. I need to loop through those names and join the first and last names, then output them to unordered list. I am having trouble visualizing what the right approach to accomplish this is.

Can someone suggest a method in CFML (I don't know CFSCRIPT very well).

Thanks!

EDIT: I should have added that both fields will always have the exact same number of entries. Thanks to all that answered -- proof that there are a lot of ways to skin a cat :)

like image 603
red4d Avatar asked Mar 30 '26 00:03

red4d


1 Answers

I would do something like

<cfloop from="1" to="#ListLen(firstnames)#" index="i">
#ListGetAt(firstnames,i)# #ListGetAt(lastnames,i)#<br>
</cfloop>

If this were a list of 5000 you would be better off putting it in a structure or an array, but for a list of ~5 this should be sufficient.

like image 107
Matt Busche Avatar answered Apr 01 '26 15:04

Matt Busche



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!