Reply to topic
CF8 and arrays acting strange
tri_3sports_dfw


Joined: 21 Aug 2007
Posts: 3
Reply with quote
Has anyone witnessed odd behavior with CF8 and Arrays? I have some code that has ran fine since CF4. Then when the server was upgraded to CF8 the site has been dead in the water.
go to www.harvestridgehoa.com to see the error live.

the following code is where the error happens.

<cfset idlist = "">
<cfset name_list = "">
<cfset linkids = #getcontent.link_to#>


<cfloop list="#linkids#" index="i" delimiters=",">
<cfoutput>
<cfloop list="#i#" index="y" delimiters="-">
<cfif #IsNumeric(y)# EQ "YES">
<cfset idlist = #ListAppend(idlist, y, ",")#>
<cfelse>
<cfset name_list = #ListAppend(name_list, y, ",")#>
</cfif>
</cfloop>
</cfoutput>
</cfloop>

<cfset idarray = #ListToArray(idlist, ",")#>
<link href="naturalimage.css" rel="stylesheet" type="text/css">

<cfoutput>
<cfif NOT IsDefined("num")>
<cfset num = 1>
</cfif>
<cfloop list="#name_list#" index="name" delimiters=",">
<tr>
<td align="left" valign="top">
<a href="index.cfm?ID=#Trim(idarray[num])#">#name#</a>
</td>
</tr>
<cfset num = IncrementValue(num)>
</cfloop>
</cfoutput>

Many thanks for any help in advance.
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
Why do you send the LIST to an ARRAY, you can just loop on the LIST.

Use this function

ListGetAt(list, position [, delimiters])

You could replace this line.
Code:

<a href="index.cfm?ID=#Trim(idarray[num])#">#name#</a>


to something like this...
Code:

<a href="index.cfm?ID=#Trim(ListGetAt(idlist, num, ","))#">#name#</a>


I did not test the code... but that should work...
tri_3sports_dfw


Joined: 21 Aug 2007
Posts: 3
Reply with quote
I the suggestion and got exactly what I thought I would. The two initial loops break apart the results of the getcontent.link_to result set. The results looks like "Blah - 1,Foo - 2". The values are inserted into either the name_list or idlist. So, the idlist would look like "1,2" and name_list like "Blah, Foo". Implementing the suggestion above causes the page to draw links with names and numbers instead of names with cooresponding numbers for the ID in the link.

Then in the final loop where the values are placed in the link. The name_list is looped over to place the name to be displayed to the user as a hyperlink. The idlist uses the index position of the array to determin the ID to be put in the address to be linked to.

This is a problem that has only surfaced since the cf8 upgrade.
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
I will take a look later at home... I got really busy this week... sorry...


But I was at your website now, and I saw that it added some extra text on the link.

Like on the home link you have this

Code:

http://www.harvestridgehoa.com/index.cfm?ID=Home - 1


And what does the result should be?
Some like this

Code:

http://www.harvestridgehoa.com/index.cfm?ID=1
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
can you display the value of your list (idlist, name_list , linkids) so I can do a test here on my computer for you
tri_3sports_dfw


Joined: 21 Aug 2007
Posts: 3
Reply with quote
No worries I really appreciate the help. Work has kept me away from this site most of the week as well.

the following is how the variables would look if printed to the screen in a working scenario:

linkids =
Home - 1,Board - 2,Committees - 3,Guidelines - 4,Contact Us - 5,Classifieds - 13,Photo Album - 14,News Letters - 15,FTW Announcements - 19

idlist = 1,2,3,4,5,13,14,15,19

name_list = Home, Board, Committees, Guidlines, Contact Us, Classifieds, Photo Album, News Letters, FTW Announcements

you are correct the link would be http://www.harvestridgehoa.com/index.cfm?ID=1 or <a href="index.cfm?ID=1">Home</a> if you viewed the source for that link

Thanks for your help it is appreciated
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
tri_3sports_dfw:

I changed your code a little be. I'm only using 2 lists, one for the number and another one for the names. If you keep then on the same order this will work.

here is the code.

Code:

<cfset idlist = "1,2,3,4,5,13,14,15,19">
<cfset name_list = "Home, Board, Committees, Guidlines, Contact Us, Classifieds, Photo Album, News Letters, FTW Announcements">

<cfoutput>
   <p>#idlist#</p>
    <p>#name_list#</p>
</cfoutput>
<br />

<cfoutput>
        <cfset counter = 1>
         <cfloop list="#idlist#" index="x">
          <p><a href="index.cfm?ID=#x#">#ListGetAt(name_list, counter, ",")#</a></p>
                <cfset counter = counter +1>
         </cfloop>
</cfoutput>


Just remember to remove your array from your code, since you will not be using it any more.
CF8 and arrays acting strange
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic