Avatar of James Rodgers
James Rodgers
Flag for Canada asked on

Logic Problem - stuck

ok i have a site with 100 pages, no db and i need to be able to cycle through the pages by chapters AND by previous next
the layout is flat, all pages are at the root, and they aren't sequential

pageABC.cfm
pageDEF.cfm
pageGHI.cfm
pageJKL.cfm
pageMNO.cfm
.....
pageXYZ.cfm
pageAABBCC.cfm
...

pages ABC,JKL, XYZ, and AABBCC are all from chapter 1
pages DEF, GHI, and TUV are all from chpater 2 i need do display a set of links as pages
when a user clicks a link to JKL i need to display links for all the pages chapter 1

e.g.:  [p1] [p2] [p3] [p4]
i also need to include previous and next options so i need to determine the next page and previous page in the sequence
so somewhere on the page i will have < and > for the previous and next pages

i am looking for a way to build an array? a structure? and array of structures ?  linked list? that will let me cycle through the the chapters and pages in the chapter so that when i hit page 4 of chapter 1 i know that the next page is actually page 1 of chapter 2 but will let me use something like structkey or structfind to locate the current page and from that determine the chapter and what is one page forward and one page backwards, if there is one, from that point

just looking for approaches on to how to solve this.

wish i could offer more points...

TIA
ColdFusion Language

Avatar of undefined
Last Comment
James Rodgers

8/22/2022 - Mon
erikTsomik

what you can do is to create a session variable. and when you click next you add 1 to the session variable otherwise subtract 1
ASKER CERTIFIED SOLUTION
Hugh Fraser

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
James Rodgers

ASKER
@hfrase
i see what you are saying, traversing the nodes and pulling the appropriate info, but could you give an example? my xml is terrible and unfortunately this will be CF5 on IIS
James Rodgers

ASKER
maybe something like

<chapter name="chp1>
	<page>
		<name>
			pg1
		</name>
		<url>
			pageABC.cfm
		</url>
		<otherattribute>
			somevalue
		</otherattribute>
	</page>
	<page>
		<name>
			pg2
		</name>
		<url>
			pageGHI.cfm
		</url>
		<otherattribute>
			somevalue
		</otherattribute>
	</page>
	<page>
		<name>
			pg3
		</name>
		<url>
			pageTUV.cfm
		</url>
		<otherattribute>
			somevalue
		</otherattribute>
	</page>
</chapter>
<chapter name="chp2>
	<page>
		<name>
			pg1
		</name>
		<url>
			pageJKL.cfm
		</url>
		<otherattribute>
			somevalue
		</otherattribute>
	</page>
	<page>
		<name>
			pg2
		</name>
		<url>
			pageXYZ.cfm
		</url>
		<otherattribute>
			somevalue
		</otherattribute>
	</page>
 
</chapter>

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Nathan Stanford Sr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
James Rodgers

ASKER
close but not exactly able to handle the complexities i need

i need to generate the following at page load, lets assume page 3 of chapter 1, chapter 1 has 4 pages

[<a href="pageABC.cfm">1</a>]
[<a href="pageJKL.cfm">2</a>]
[<a href="pageXYZ.cfm" style="onlink">3</a>]
[<a href="pageAABBCC.cfm">4</a>]

AND

<a href="pageJKL.cfm"><<Previous</a>
<a href="pageAABBCC.cfm">Next>></a>



the problem comes up when the active page is the last, or first, page in a chapter

[<a href="pageABC.cfm" title="some text about page1">1</a>]
[<a href="pageJKL.cfm" title="some text about page2">2</a>]
[<a href="pageXYZ.cfm" title="some text about page3">3</a>]
[<a href="pageAABBCC.cfm" title="some text about page4" style="onlink">4</a>]

AND

<a href="pageXYZ.cfm"><<Previous</a>
<a href="page1Chapter2.cfm">Next>></a>


i could simply have a list of all the pages

<cfset pageList ="cip1,c1p2,c1p3,c1p4.....c9p10">
<cfset pageListText ="some text about Chapt 1 page1,some text about Chapt 1 page2,some text about Chapt 1 page3,some text about Chapt 1 page4.....some text about Chapt 9 page10">

but it would be horrid to mainatian

so i considered an array of structure
<!--- DO NOT EDIT --->
<cfset iSequence = 0>
<cfset hNavArray = ArrayNew(1)>
<!--- END DO NOT EDIT --->

<cfset sLinkClassName = "pNav">                                                             <!--- css class name for links in this module --->
<cfset sDivider = '<img src="/images/pNav_divider.gif">'>                         <!--- image or text separating menu items --->
<cfset sImagesDirectory = "/images">


<!--- Adding Nav Item --->
<cfset iSequence = iSequence + 1>                                                            
<cfset hNavArray[iSequence] = StructNew()>                                                
<cfset hNavArray[iSequence].url = "/p_home.cfm">                                      
<cfset hNavArray[iSequence].img = "/pNav_home_nm.gif">                               
<cfset hNavArray[iSequence].alt = "Home">             

<cfset iSequence = iSequence + 1>                                                            
<cfset hNavArray[iSequence] = StructNew()>                                                
<cfset hNavArray[iSequence].url = "/p_aboutjkh.cfm">                                 
<cfset hNavArray[iSequence].img = "/pNav_aboutjkh_nm.gif">                         
<cfset hNavArray[iSequence].alt = "About">                                                 
<cfset hNavArray[iSequence].onWhenURLHas ="_aboutjkh">

but i still need a quick way to locate the current page in the array and its siblings, if any and all the pages in a chapter, looping would be too intensive i think
Nathan Stanford Sr

I see maintenance problems in anything you choose....
I think I am not seeing all of the picture.  So why no database?  Is your site hosted somewhere where there is not database?

You could create an XML file and make it your database if you have the rights to Save a file....




James Rodgers

ASKER
there is no db support for this site, i have full write permission to any directory, my xml skills are 0, as in never used it before, and this is cf5 on iis

i could use a text file as a db source, but if i make anything it needs to be simple enough for a non programmer to manage the source to add, remove or resequence the pages at need without having to redo code

that's whats getting me stuck
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
James Rodgers

ASKER
i have gone with a simplified version of the code in my last post, thanks for the help
gdemaria

Hey Jester, sorry to join late, but I thought about this last night and like the array approach.   An array of structures as with your last example.

 <cfset pos = arrayLen(PageArray) + 1>
 <cfset PageArray[pos] = structNew()>
 <cfset pageArray[pos].file = "p_aboutJHK.cfm">
 <cfset pageArray[pos].chapter = "1">
 <cfset pageArray[pos].page     = "4">
 <cfset pageArray[pos].title       = "About JKH">


I had envisioned a simple function that would allow you to add pages and automatically update the next page number for you (the 4 in the above example).

To locate the page, some code at the top of each file that loops through the array to match the template's name and then pull out the chapter and page number.  Since it's in a sequencial array, it's easy to determine the next/prev pages.

If you're interested in chatting about this, let me know.  You may already be set though..

James Rodgers

ASKER
what i did was created an array of structures
i loop through the array and use structFindValue to locate the page

when i do that i assign the "found" structure to a new structure using structCopy
then if the index of the found structure > 1 it has at least one sibling before it and i pull the necessary values from the "older" sibling and if the index < the array length it has at least one "younger" sibling so grab the necessary values form the structure at index+1
 
see code, not elegant, but it works



<!--- define the previous current and next pages in the sequence --->
<!--- some variables to cut down on long if condition checks later in the page ---> 
<cfset arrIndex=0>
<cfset hasPrevious =false>
<cfset hasNext =false>
<!--- look for this page in the  array  - search by value --->
<cfloop from="1" to="#arrayLen(hNavArray)#" index="idx">
	<cfset myvar= structFindValue(hNavArray[idx], listlast(GetBaseTemplatePath(),'/\'))>  <!--- page name - always unique --->
	
	<cfif arrayLen(myVar)> <!--- found page name value - mark where found --->
		<cfset arrIndex=#idx#>	
	</cfif>
</cfloop>
<!--- the currentpage was found --->
<!--- copy the found page structure to the current page --->
<cfif arrIndex>
	<cfset currentPage=structCopy(hNavArray[arrIndex])>
	<cfset currpage= "#currentpage.pageurl#">
	<cfset primarytitle	= #currentpage.pagetitle#> 				
	<cfset secondarytitle = #currentpage.secondarytitle#> 		
	<cfset spagetitle		=   "#primarytitle#">		
	<cfif len(secondarytitle)>
		<cfset spagetitle ="#spagetitle# - #secondarytitle#">
	</cfif>
	<cfset template	= #currentpage.pagetemplate#>		
</cfif>
<!--- if there is a previous page set it here --->
<cfif arrIndex GT 1>
	<cfset previousPage=structCopy(hNavArray[arrIndex-1])>
	<cfset prevurl="/AR2008/#nextPage.pageurl#">
	<cfset prevtitle="#nextPage.alttext#">
	<cfset hasPrevious =true>
</cfif>
<!--- if there is a next page set it here --->
<cfif arrIndex LT arrayLen(hNavArray)>
	<cfset nextPage=structCopy(hNavArray[arrIndex+1])>
	<cfset nexturl="/AR2008/#nextPage.pageurl#">
	<cfset nexttitle="#nextPage.alttext#">
	<cfset hasNext=true>
</cfif>

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Nathan Stanford Sr

Sorry, I did not get back to you busy at work.
gdemaria

Ok, looks good.  If you want so ideas on the code... ?


This loop may work a tad faster for you.   It compares only the structure you want to compare (structure find searches all structures elements even the ones that could not hold the value).  The loop also breaks once found.


<cfset thisPage = listlast(GetBaseTemplatePath(),'/\')>  <!--- remember page to avoid recalculating --->
<cfloop from="1" to="#arrayLen(hNavArray)#" index="idx">
   <cfif hNavArray[idx].pageURL is thisPage> <!---- only check the one structure for a match, save time ---->
      <cfset arrIndex = idx>
      <cfbreak> <!----found it, so stop looping --->
   </cfif>
</cfloop>

Open in new window

gdemaria

Is it necessary for you to place the values into another variable?

In this code you are copying the values twice (once into another structure and then once into the variable scope)

<cfif arrIndex>
      <cfset currentPage=structCopy(hNavArray[arrIndex])>
      <cfset currpage= currentpage.pageurl>
      <cfset primarytitle      = #currentpage.pagetitle#>                         
      <cfset secondarytitle = #currentpage.secondarytitle#>             
      <cfset spagetitle            =   "#primarytitle#">            
      <cfif len(secondarytitle)>
            <cfset spagetitle ="#spagetitle# - #secondarytitle#">
      </cfif>
      <cfset template      = #currentpage.pagetemplate#>            
</cfif>

<cfset currentPage=hNavArray[arrIndex]> <!--- no need to COPY the structe ---> 
 
Now you could just reference this..
<cfoutput>#currentpage.pageurl#</cfoutput>
 
Instead of copying again...

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
gdemaria

And one more... this looks like a type-o

<cfif arrIndex GT 1>
      <cfset previousPage=structCopy(hNavArray[arrIndex-1])>
      <cfset prevurl="/AR2008/#nextPage.pageurl#">
      <cfset prevtitle="#nextPage.alttext#">
      <cfset hasPrevious =true>
</cfif>

You have previousPage in the first line but then reference NextPage in the 2nd and 3rd lines.


James Rodgers

ASKER
thanks all, i will clean up the code, this is the first draft, i like to get things working then i can worry about cleaning it up ;)

and thanks for the code change suggestions

>>Is it necessary for you to place the values into another variable?
the variables were the original output references, this house, for some reason, likes to copy variables, just how they do things i guess, but i'm working on changing them