Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I do a RecordCount in 5's 2

Status
Not open for further replies.

monoone

Programmer
May 24, 2002
219
0
0
US
I have thumbnail images -

The way it's laid out is by 5's per line.

The code that I have will only generate 1 per line.

How do I make this code generate 5 images per line with a maximum output of 15 per page with a link to the next 15?

Here is the code that generates 1 image per line. It works great but does not fit my design.

Can anyone help?

--------Code--------------------

<table width=&quot;500&quot; cellspacing=&quot;10&quot; cellpadding=&quot;10&quot; border=&quot;0&quot;>
<tr>
<td valign=&quot;top&quot; width=&quot;500&quot;>
<!--- Set the number of records to display on each page. --->
<CFSET OnEachPage = 15>
<!--- Set the default startrow to 1 if a value was not passed. --->
<!--- Determine whether or not to show the previous or next links. --->
<CFPARAM NAME = &quot;StartRow&quot; DEFAULT = &quot;1&quot;>
<!--- Set the value of endrow to the maxrows + startrow - 1 --->
<CFSET EndRow = StartRow + OnEachPage - 1>
<!--- If the end row is greater than the recordcount, determine how many records are left. --->
<CFIF EndRow GTE getThumb.RecordCount>
<CFSET EndRow = getThumb.RecordCount>
<CFSET Next = false>
<!--- Othereise, set Next to true and determine the next set of records. --->
<CFELSE>
<CFSET Next = true>
<CFIF EndRow + OnEachPage GT getThumb.RecordCount>
<CFSET NextNum = getThumb.RecordCount - EndRow>
<CFELSE>
<CFSET NextNum = OnEachPage>
</CFIF>
<CFSET NextStart = EndRow + 1>
</CFIF>
<!--- If StartRow is 1, set Previous to false. --->
<CFIF StartRow IS 1>
<CFSET Previous = false>
<!--- Othewise, determine the previous set of records. --->
<CFELSE>
<CFSET Previous = true>
<CFSET PreviousStart = StartRow - OnEachPage>
</CFIF>

<!--- Determine how many pages will be displayed. --->
<CFSET NumPages = Ceiling(getThumb.RecordCount / OnEachPage)>
<CFPARAM NAME = &quot;PageNum&quot; DEFAULT = &quot;1&quot;>
<CFOUTPUT>
Now displaying posts <FONT COLOR=&quot;Red&quot;>#StartRow# to #EndRow# of #getThumb.RecordCount#.
</CFOUTPUT>
<br>
<br>
Click on The desired Piece for More Information:
<CFOUTPUT QUERY=&quot;getThumb&quot; STARTROW = &quot;#startrow#&quot; MAXROWS = &quot;#OnEachPage#&quot;>
<br>
<br>
<a href=&quot;GalleryDetail.cfm?ProdID=#ProdID#&quot;><img src=&quot;img/#ThumbImage#&quot; border=&quot;1&quot; alt=&quot;&quot; style=&quot;border-color: Black;&quot;></A>
</cfoutput>

<!--- If Previous is true, display the previous link. --->
<CFIF Previous>
<CFOUTPUT>
<A HREF = &quot;galleryLook.cfm?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#<CFIF IsDefined(&quot;Keyword&quot;)>&Keyword=#URLEncodedFormat(Keyword)#</CFIF>&quot;>&lt;&lt;&nbsp;Previous</A>
</CFOUTPUT>
<CFELSE>
&nbsp;
</CFIF>
<CFLOOP FROM = &quot;1&quot; TO = &quot;#NumPages#&quot; INDEX = &quot;ThisPage&quot;>
<CFOUTPUT>
<CFIF ThisPage IS PageNum>
#ThisPage#
<CFELSE>
<CFSET PageNumStart = (((ThisPage - 1) * OnEachPage) + 1)>
<A HREF = &quot;galleryLook.cfm?StartRow=#PageNumStart#&PageNum=#ThisPage#<CFIF IsDefined(&quot;Keyword&quot;)>&Keyword=#URLEncodedFormat(Keyword)#</CFIF>&quot;>#ThisPage#</A>
</CFIF>
</CFOUTPUT>
</CFLOOP>

<!--- If Next is true, display the previous link. --->
<CFIF Next>
<CFOUTPUT>
<A HREF = &quot;galleryLook.cfm?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#<CFIF IsDefined(&quot;Keyword&quot;)>&Keyword=#URLEncodedFormat(Keyword)#</CFIF>&quot;>Next&nbsp;&gt;&gt;</A>
</CFOUTPUT>
<CFELSE>
&nbsp;
</CFIF>
</td>

------------------------------------------

Thanks,

Eric
 
I did a 4 per row thumbnail setup for a card site.. here's my code:

Code:
<TABLE width=&quot;100%&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot;>
<CFOUTPUT query=&quot;GetImages&quot;><CFSET imgLink=&quot;<DIV align=&quot;&quot;center&quot;&quot;><A href=&quot;&quot;/members/cardform.cfm?ImageID=#ImageID#&quot;&quot;><IMG src=&quot;&quot;[URL unfurl="true"]http://www.alfii.com/images/#imageURL#&quot;&quot;[/URL] width=&quot;&quot;100&quot;&quot;><BR>#ImageURL#</A></DIV>&quot;>
 <CFIF tdcount eq 1>
  <TR><TD width=&quot;25%&quot;>#imgLink#</TD>
 <CFELSEIF tdCount eq 2>
  <TD width=&quot;25%&quot;>#imgLink#</TD>
<CFELSEIF tdCount eq 3>
  <TD width=&quot;25%&quot;>#imgLink#</TD>
<CFELSEIF tdCount eq 4>
  <TD width=&quot;25%&quot;>#imgLink#</TD></TR>
<CFIF recordcount is not currentrow><CFSET tdCount=0></CFIF></CFIF>
<CFIF recordcount is currentrow><CFIF tdCount eq 1>
  <TD colspan=&quot;3&quot; width=&quot;75%&quot;>&nbsp;</TD></TR>
<CFELSEIF tdCount eq 2>
  <TD colspan=&quot;2&quot; width=&quot;50%&quot;>&nbsp;</TD></TR>
<CFELSEIF tdCount eq 3>
  <TD colspan=&quot;1&quot; width=&quot;25%&quot;>&nbsp;</TD></TR>
</CFIF></CFIF><CFSET tdCount=tdCount + 1>
</CFOUTPUT></TABLE>

This created a proper table for me.. and should work for you too with some modifications...

Tony Did I help?
Vote!
 
For some reason this wont work -

Error--------------

Error Diagnostic Information

An error occurred while evaluating the expression:


tdcount eq 1



Error near line 180, column 21.
--------------------------------------------------------------------------------

Error resolving parameter TDCOUNT


ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.


The error occurred while processing an element with a general identifier of (CFIF), occupying document position (180:8) to (180:26).
---------------------------------------

The code-------------------------------

<td valign=&quot;top&quot; width=&quot;500&quot;>
<CFOUTPUT query=&quot;GetThumb&quot;>
<CFSET imgLink=&quot;<a href=GalleryDetail.cfm?ProdID=#ProdID#><img src=img/#ThumbImage# border=1 style=border-color: Black;></A>&quot;>
<CFIF tdcount eq 1>
<TR><TD width=&quot;25%&quot;>#imgLink#</TD>
<CFELSEIF tdCount eq 2>
<TD width=&quot;25%&quot;>#imgLink#</TD>
<CFELSEIF tdCount eq 3>
<TD width=&quot;25%&quot;>#imgLink#</TD>
<CFELSEIF tdCount eq 4>
<TD width=&quot;25%&quot;>#imgLink#</TD></TR>
<CFIF recordcount is not currentrow><CFSET tdCount=0></CFIF></CFIF>
<CFIF recordcount is currentrow><CFIF tdCount eq 1>
<TD colspan=&quot;3&quot; width=&quot;75%&quot;> </TD></TR>
<CFELSEIF tdCount eq 2>
<TD colspan=&quot;2&quot; width=&quot;50%&quot;> </TD></TR>
<CFELSEIF tdCount eq 3>
<TD colspan=&quot;1&quot; width=&quot;25%&quot;> </TD></TR>
</CFIF></CFIF><CFSET tdCount=tdCount + 1>
</CFOUTPUT>
</td>

-----------------------------------------

Any ideas?
 
prefix the code with <CFSET tdcount=1> Did I help?
Vote!
 
Oh okay, I'll try that tonight. Thanks!

Eric
 
I think there is a simpler way to accomplish what you want. To divide your master list of images into groups of 15 make a list of their id number and then change the delimiter for every 15th image. (I changed it from a comma to a tilde in the sample below.) Use this to cycle through your list in groups of 15.

To put five images on a line (after you have determined which 15 you want) use the MOD operator to check and see if the CurrentRow variable is divisible by five.

<!--- Get a list of all possible items --->
<cfquery datasource=&quot;#yourdatasource#&quot;
name=&quot;masterlist&quot;>
select id from #yourtablename#
order by #yoursortmethod#
</cfquery>

<!--- Divide the list into groups of 15 per page by
changing the delimiter from a comma to a tilde --->
<cfset newlist = &quot;&quot;>
<cfloop query=&quot;masterlist&quot;>
<cfif CurrentRow MOD 15 eq 0>
<cfset newlist = newlist & &quot;#id#~&quot;>
<cfelse>
<cfset newlist = newlist & &quot;#id#,&quot;>
</cfif>
</cfloop>

<!--- Determine which set of 15 we are presently
working with --->
<cfif IsDefined('URL.newlist') is false>
<cfset activeset = ListGetAt(newlist, 1, &quot;~&quot;)>
<cfelse>
<cfset activeset = URL.newlist>
</cfif>

<table border=&quot;1&quot;>
<tr>
<td colspan=&quot;5&quot;>
<!--- Make a list of each set of 15 for the
navigation bar --->
<cfset Loopcounter = 0>
<cfloop list=&quot;#newlist#&quot; index=&quot;thisset&quot;
delimiters=&quot;~&quot;>
<cfset Loopcounter = Loopcounter + 1>
<cfif activeset is not thisset>
<cfoutput><a
href=&quot;test_cycle.cfm?newlist=#thisset#&quot;>#Loopcounter#</a></cfoutput>
</cfif>
</cfloop>
</td>
</tr>
<cfquery dbtype=&quot;query&quot; name=&quot;displayset&quot;>
select * from masterlist where id in (#activeset#)
</cfquery>
<tr>
<cfoutput query=&quot;displayset&quot;>
<!--- Is This the start of a new row --->
<cfif CurrentRow MOD 5 eq 1><tr></cfif>
<td>#id#</td>
<!--- Is This the end of the current row --->
<cfif CurrentRow MOD 5 eq 0></tr></cfif>
</cfoutput>
</table>
 
Hi There;

They both work great thank you but how would I have a link to the next 15 images and so on?

My design only caters to 15 of these images (I hate scrolling) so I need to link to the next 15 images.

Any help would be great

Thanks,

Eric
 
monoone, the link to next is generated as one of the several links produced by

<cfset Loopcounter = 0>
<cfloop list=&quot;#newlist#&quot; index=&quot;thisset&quot;
delimiters=&quot;~&quot;>
<cfset Loopcounter = Loopcounter + 1>
<cfif activeset is not thisset>
<cfoutput><a href=&quot;test_cycle.cfm?newlist=#thisset#&quot;
>#Loopcounter#</a></cfoutput>
</cfif>
</cfloop>

gelgard, that's a slick technique

it even lets you call the page with newlist=&quot;3,57,112&quot; if you wanted to for some reason

in the code snippet above, i would not exclude the activeset, i would use cfelse to print loopcounter without a link around it


rudy
 
My preference would be to show them a list of all the data sets (rather than just previous and next) and I like the idea of having a link to print the presently displayed set.

Presuming that you wanted to stick with just having links to the previous and next data set there is another way to do it which does not involve looping through the entire list.

You can use ListFind() to search for the position of the active dataset and then build links to only the next and previous sets. You just have to be careful that you deal with the start and the end of the list.

I redid the the code in the verbose tack on below but the changes come in the red section.

Thanks for the kind words r937.

Code Sample
<!--- Get a list of all possible items --->
<cfquery datasource=&quot;#yourdatasource#&quot; name=&quot;masterlist&quot; maxrows=&quot;45&quot;>
select id from #yourtablename#
order by #yoursortorder#
</cfquery>

<!--- Divide the list into groups of 15 per page by changing the delimiter from a comma to a tilde --->
<cfset newlist = &quot;&quot;>
<cfloop query=&quot;masterlist&quot;>
<cfif CurrentRow MOD 15 eq 0>
<cfset newlist = newlist & &quot;#id#~&quot;>
<cfelse>
<cfset newlist = newlist & &quot;#id#,&quot;>
</cfif>
</cfloop>

<!--- Determine which set of 15 we are presently working with --->
<!--- Build links to the previous and next sets of data --->
<cfif IsDefined('URL.newlist') is false>
<!--- We are using the first set so build links to the next set and an error message for the previous set --->
<cfset activeset = ListGetAt(newlist, 1, &quot;~&quot;)>
<cfset previouslink = &quot;javascript:alert('This is the first set of images.')&quot;>
<cfset nextset = ListGetAt(newlist, 2, &quot;~&quot;)>
<cfset nextlink = &quot;test_cycle.cfm?newlist=#nextset#&quot;>
<cfelse>
<cfset activeset = URL.newlist>
<cfset tmp = ListFind(newlist, activeset, &quot;~&quot;)>
<!--- Build a link to the previous set of data --->
<cfif tmp gt 1>
<!--- We are past the first set so the previous link should point to real data --->
<cfset previousset = ListGetAt(newlist, tmp - 1, &quot;~&quot;)>
<cfset previouslink = &quot;test_cycle.cfm?newlist=#previousset#&quot;>
<cfelse>
<!--- There is no previous set so build an error message for the user. --->
<cfset previouslink = &quot;javascript:alert('This is the first set of images.')&quot;>
</cfif>
<cfif tmp eq ListLen(newlist, &quot;~&quot;)>
<!--- We are at the end of the list so build an error message --->
<cfset nextlink = &quot;javascript:alert('This is the last set of images.')&quot;>
<cfelse>
<cfset nextset = ListGetAt(newlist, tmp + 1, &quot;~&quot;)>
<cfset nextlink = &quot;test_cycle.cfm?newlist=#nextset#&quot;>
</cfif>
</cfif>


<table border=&quot;1&quot;>
<tr>
<td colspan=&quot;5&quot;>
<cfoutput>
<a href=&quot;#previouslink#&quot;>Previous</a>
<a href=&quot;#nextlink#&quot;>Next</a>

</cfoutput>
</td>
</tr>
<cfquery dbtype=&quot;query&quot; name=&quot;displayset&quot;>
select * from masterlist where id in (#activeset#)
</cfquery>
<tr>
<cfoutput query=&quot;displayset&quot;>
<!--- Is This the start of a new row --->
<cfif CurrentRow MOD 5 eq 1><tr></cfif>
<td>#id#</td>
<!--- Is This the end of the current row --->
<cfif CurrentRow MOD 5 eq 0></tr></cfif>
</cfoutput>
</table>
 
Wow!

When I get home I shall try this.

Thanks gelgaard, r937 and webmigit!

Monoone
 
Hello;

I am getting an error -

--Error--------------

Error Diagnostic Information

An error occurred while evaluating the expression:


nextset = ListGetAt(newlist, 2, &quot;~&quot;)



Error near line 196, column 17.
--------------------------------------------------------------------------------

In function ListGetAt(list, index [, delimiters]) the value of index, which is 2, is not a valid index for the list given as a the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list


The error occurred while processing an element with a general identifier of (CFSET), occupying document position (196:11) to (196:54).


Date/Time: 10/16/02 18:47:47
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)
Remote Address: 207.5.162.64
HTTP Referer: -------------------------------------------------

Here is my code:

-----------------------------------------------

SQL-----------------------------

<cfquery name=&quot;GetThumb&quot; datasource=&quot;JZDB&quot; maxrows=45 dbtype=&quot;ODBC&quot;>
Select *
FROM Product

WHERE CatID = 3


</cfquery>

------------------------------------

Output Code------------------------

<!--- Divide the list into groups of 15 per page by changing the delimiter from a comma to a tilde --->
<cfset newlist = &quot;&quot;>
<cfloop query=&quot;GetThumb&quot;>
<cfif CurrentRow MOD 15 eq 0>
<cfset newlist = newlist & &quot;#ThumbImage#~&quot;>
<cfelse>
<cfset newlist = newlist & &quot;#ThumbImage#,&quot;>
</cfif>
</cfloop>

<!--- Determine which set of 15 we are presently working with --->
<!--- Build links to the previous and next sets of data --->

<cfif IsDefined('URL.newlist') is false>
<!--- We are using the first set so build links to the next set and an error message for the previous set --->

<cfset activeset = ListGetAt(newlist, 1, &quot;~&quot;)>
<cfset previouslink = &quot;javascript:alert('This is the first set of images.')&quot;>
<cfset nextset = ListGetAt(newlist, 2, &quot;~&quot;)>
<cfset nextlink = &quot;GalleryDetail.cfm?newlist=#nextset#&quot;>
<cfelse>
<cfset activeset = URL.newlist>
<cfset tmp = ListFind(newlist, activeset, &quot;~&quot;)>

<!--- Build a link to the previous set of data --->
<cfif tmp gt 1>

<!--- We are past the first set so the previous link should point to real data --->
<cfset previousset = ListGetAt(newlist, tmp - 1, &quot;~&quot;)>
<cfset previouslink = &quot;GalleryDetail.cfm?newlist=#previousset#&quot;>
<cfelse>

<!--- There is no previous set so build an error message for the user. --->
<cfset previouslink = &quot;javascript:alert('This is the first set of images.')&quot;>
</cfif>
<cfif tmp eq ListLen(newlist, &quot;~&quot;)>

<!--- We are at the end of the list so build an error message --->
<cfset nextlink = &quot;javascript:alert('This is the last set of images.')&quot;>
<cfelse>
<cfset nextset = ListGetAt(newlist, tmp + 1, &quot;~&quot;)>
<cfset nextlink = &quot;GalleryDetail.cfm?newlist=#nextset#&quot;>
</cfif>
</cfif>

<table border=&quot;1&quot;>
<tr>
<td colspan=&quot;5&quot;>
<cfoutput>
<a href=&quot;#previouslink#&quot;>Previous</a>
<a href=&quot;#nextlink#&quot;>Next</a>
</cfoutput>
</td>
</tr>
<cfquery dbtype=&quot;odbc&quot; datasource=&quot;JZDB&quot; name=&quot;displayset&quot;>
SELECT *
FROM Product
WHERE ProdID IN (#activeset#)
</cfquery>
<tr>
<cfoutput query=&quot;displayset&quot;>

<!--- Is This the start of a new row --->
<cfif CurrentRow MOD 5 eq 1><tr></cfif>
<td>#ThumbImage#</td>

<!--- Is This the end of the current row --->
<cfif CurrentRow MOD 5 eq 0></tr></cfif>
</cfoutput>
</td>

--------------------------------------------

I have no clue how to fix this...

Any ideas??
 
I reproduced the same error when my masterlist query returned less than 15 items. Make sure the total record count for your &quot;GetThumb&quot; query is over 15. The ListGetAt() call is parsing the list in groups of 15. i.e. The first 15 thumbnails are considered one list entry. The second 15 the second entry, etc.
 
Okay - I entered 2 more items so I would have 15 -

The question is - what if there are only 10 items in the db i.e An item is discontinued -

Also now I get this error -

-Thanks
Monoone

----Errror

An error occurred while evaluating the expression:


nextset = ListGetAt(newlist, 2, &quot;~&quot;)



Error near line 198, column 17.
--------------------------------------------------------------------------------

In function ListGetAt(list, index [, delimiters]) the value of index, which is 2, is not a valid index for the list given as a the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list


The error occurred while processing an element with a general identifier of (CFSET), occupying document position (198:11) to (198:54).


Date/Time: 10/16/02 19:47:53
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)
Remote Address: 207.5.162.64
HTTP Referer:
 
My code presumes you have more than 15 records (more than one page of data) returned in your thumbnails query. I used a sample that generated 45 results. That guaranteed me three pages of data to display that allowed me to test the next and previous link code.

If there are less than 15 thumbnails in your query results than why are you building a page with these features?
 
Seems to me that what monoone is wanting to do is make a recordset nav for a small collection that's growing, its easier to do the work in the beginning then have to patch and duct tape it in a while...

Monoone, what I'd suggest is either use my code (very shameless plug) or use cfif listlen's.. IE... <CFIF listlen(newlist) gte tmp + 1>...listgetat procedure here...<CFELSE>...set involved variables to null... (&quot;&quot; or random number like 1548432 or 0)</CFIF> and then in the output of the variables, us a cfif... like <CFIF nextset neq 1548432>...show next link...</CFIF>...

Goodnight,
Tony Did I help?
Vote!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top