I'm working on a basic photo upload script and there are some chunks of code that repeat like a loop, but I've had to write them out an explicit amount of times because I can't put a variable within a variable.
Every instance has variable names that increment, such as "primary_1" to "primary_2".
Primary_1 is a variable. In order to loop through that, I would need to make a variable within a variable.
like #primary_#loop##
or worse
#photo_info_#loop#.profile_photo_public_url#
Here is a chunk of code that explains what I am talking about. If someone can show me how to reduce this 2 block chunk of code into 1 block with a loop clause, I would be forever grateful. I could reduce a 3,000 line script down to about 1,000 lines.
<CFIF isDefined("set_as_primary") AND (FORM.set_as_primary EQ "primary_1")>
<CFQUERY NAME="update_profile_thumbnail" datasource="members">
UPDATE tbl_profiles
SET profile_thumbnail_url = '#photo_info_1.profile_photo_public_url#',
profile_thumbnail_file = '#photo_info_1.profile_photo_file#'
WHERE (member_id = #MYID#)
;
</CFQUERY>
</CFIF>
<CFIF isDefined("set_as_primary") AND (FORM.set_as_primary EQ "primary_2")>
<CFQUERY NAME="update_member_profile_thumbnail" datasource="members">
UPDATE tbl_profiles
SET profile_thumbnail_url = '#photo_info_2.profile_photo_public_url#',
profile_thumbnail_file = '#photo_info_2.profile_photo_file#'
WHERE (member_id = #MYID#)
;
</CFQUERY>
</CFIF>
Every instance has variable names that increment, such as "primary_1" to "primary_2".
Primary_1 is a variable. In order to loop through that, I would need to make a variable within a variable.
like #primary_#loop##
or worse
#photo_info_#loop#.profile_photo_public_url#
Here is a chunk of code that explains what I am talking about. If someone can show me how to reduce this 2 block chunk of code into 1 block with a loop clause, I would be forever grateful. I could reduce a 3,000 line script down to about 1,000 lines.
<CFIF isDefined("set_as_primary") AND (FORM.set_as_primary EQ "primary_1")>
<CFQUERY NAME="update_profile_thumbnail" datasource="members">
UPDATE tbl_profiles
SET profile_thumbnail_url = '#photo_info_1.profile_photo_public_url#',
profile_thumbnail_file = '#photo_info_1.profile_photo_file#'
WHERE (member_id = #MYID#)
;
</CFQUERY>
</CFIF>
<CFIF isDefined("set_as_primary") AND (FORM.set_as_primary EQ "primary_2")>
<CFQUERY NAME="update_member_profile_thumbnail" datasource="members">
UPDATE tbl_profiles
SET profile_thumbnail_url = '#photo_info_2.profile_photo_public_url#',
profile_thumbnail_file = '#photo_info_2.profile_photo_file#'
WHERE (member_id = #MYID#)
;
</CFQUERY>
</CFIF>
