Skip to main content
Known Participant
January 23, 2020
Answered

Displaying images in rows of 5

  • January 23, 2020
  • 5 replies
  • 2582 views

Hello,

 

I have about 500 images that I want to display in rows of 5. Currently, I only know how to display them in 1 vertical column like this:

 

<CFOUTPUT QUERY="List" GROUP="AuthorID">
<CFOUTPUT>
<TR>
<TD ALIGN="left" VALIGN="top" WIDTH="542" style="padding-left:2em;text-indent:-2em"><A HREF="#request.BaseURL#/book.cfm?-#URL_Title#-&BookID=#BookID#"><img src="#request.BaseURL#/images/#Image#" width="50"></A></TD>
</TR>
</CFOUTPUT>
</CFOUTPUT>

 

Thank you for your help!

This topic has been closed for replies.
Correct answer Dave Watts

If you're not actually using those variables in your code later on, you don't need them. If you are, you may need them.

 

Dave Watts, Eidolon LLC

5 replies

WolfShade
Legend
February 6, 2020

CFPARAM is a way to define and set a value to a variable IF the variable does not already exist.  If it does exist, nothing happens, the value does not change.  It's akin to:

 

<cfif NOT StructKeyExists(variables,'thisVar')>

<cfset thisVar = "foo" />

</cfif>

 

HTH,

 

^ _ ^

BookBookAuthor
Known Participant
February 7, 2020

Thanks. It sounds like you're saying that I don't need any of the <cfparam> lines then. Is that correct?

Dave WattsCommunity ExpertCorrect answer
Community Expert
February 8, 2020

If you're not actually using those variables in your code later on, you don't need them. If you are, you may need them.

 

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC
WolfShade
Legend
January 27, 2020

Actually, Dave's offering was pretty close to what you are looking for, except the opening TR needs to be before the CFOUTPUT and the closing TR should be after the /CFOUTPUT.

 

<table border="0" width="582" cellspacing="0" cellpadding="0" align="center">
	<tr>
	<cfoutput query="List">
		<td align="center" valign="top" width="542" style="padding-left:2em;text-indent:-2em">
			<a href="#request.BaseURL#/book.cfm?-#URL_Title#-&BookID=#BookID#"><img src="#request.BaseURL#/images/#Image#" width="75"></a>
		</td><cfif List.currentrow % 5 eq 0 AND List.currentrow neq List.recordCount>
	</tr>
	<tr>
	</cfif>
	</cfoutput>
	</tr>
</table>

 

This will start a TR, insert 5 TDs, then close and open another TR.  (% 5 is modulous of 5; when 0, the current row is evenly divisible by 5 and will start a new row as long as it's not the last record in the set.)

 

But Dave is right about reducing your CFOUTPUT.. since you're now ordering by serial_no first, the grouping is unnecessary, esp since you're not actually displaying anything about the serial_no.

 

HTH,

 

^ _ ^

Community Expert
January 27, 2020

Good catch!

 

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC
WolfShade
Legend
January 24, 2020

Hi, 123proust,

 

I would like to offer some constructive criticism, if I may.  In your select, you are using * to get everything.  I can be a bit pedantic, and would like to suggest that you definitively name each column in your Inventory table, as using * forces the database to reference an internal table to get the column names.  Additionally, if you do not require every column in that table, then you are pushing unneeded data across the network and adding unnecessary processing to the CPU.

 

If you are grouping by series number, then that should be reflected in your query using the GROUP BY clause.

 

As far as listing only the first 100, that will depend upon what flavor of database server you are using, as MS-SQL is slightly different from Oracle, which (I believe) is slightly different than MySQL, and so on.  Some people will just grab every record and use CF code for pagination.  This is not recommended.  At least not by me.  One should set the limits within the query and pass a page number or some such to the database in the query, and get only the desired records.

 

Now that you are grouping by series number, do you plan to display the series number in the output?  Or is there a related name that you would display?  Or is it just for grouping and the value not important?

 

V/r,

 

^ _ ^

 

UPDATE:  Thank you for marking my answer as correct.  I do appreciate it.

BookBookAuthor
Known Participant
January 25, 2020

I'm using an MS-SQL database. Thank you for explaining why I should list my database columns instead of writing "Inventory.*". However, the page wouldn't load when I wrote "Inventory.Series_no".

 

Taking your 2nd suggestion, I changed the code to read "ORDER BY Series_no" which seemed to have the desired effect. Now I need to know how to limit the results to the first 100 numbers. I do not plan to display the numbers, just the corresponding images.

 

Since I borrowed code from another page where the books were grouped by Author to make my page where the books are grouped by Series Number, the code is cluttered with lines that are probably unnecessary. I'm hoping you can tell me which lines to delete.

BookBookAuthor
Known Participant
January 27, 2020

Did you confirm that this is actually the name of your field, as I asked earlier? I'm not trying to be pushy, but if you got an error trying to refer to it directly in your query there's some sort of problem.

 

Dave Watts, Eidolon LLC


Yes, that's the name of my field. I just typed it wrong before. 

BookBookAuthor
Known Participant
January 24, 2020

Thank you, that worked great! You pointed out that I'm grouping by author. I meant to group, or order, the 500 book cover images by their Series Number (the "Series_no" Table in Inventory). This is as far as I got. Can you please help me do this, and teach me how to limit the list to the first 100 in the series? Here's as far as I got with your code and code that belonged to another page. 

 

<CFPARAM NAME="attributes.action" DEFAULT="">
<CFPARAM NAME="attributes.dsn" DEFAULT="">
<cfparam name="browseBy" default="Author">
<cfparam name="attributes.AuthorFirstName" default="">


<CFQUERY DATASOURCE="#request.MainDSN#" NAME="List">
SELECT Inventory.*,
Authors.AuthorID,
Authors.AuthorFirstName,
Authors.AuthorLastName,
Authors.Pseudonym
FROM Inventory
INNER JOIN
Authors
ON Authors.AuthorID=Inventory.AuthorID
ORDER BY AuthorLastName, AuthorFirstName, Title
</CFQUERY>

 

<TABLE BORDER="0" WIDTH="582" CELLSPACING="0" CELLPADDING="0" ALIGN="center">
<CFOUTPUT QUERY="List" group="Series_no">
<TR>
<CFOUTPUT>
<TD ALIGN="center" VALIGN="top" WIDTH="542" style="padding-left:2em;text-indent:-2em">
<A HREF="#request.BaseURL#/book.cfm?-#URL_Title#-&BookID=#BookID#"><img src="#request.BaseURL#/images/#Image#" width="75"></A>
</TD><cfif List.currentrow % 5 eq 0 AND List.currentrow neq List.recordCount>
</tr>
<tr>
</cfif>
</CFOUTPUT>
</TR>
</CFOUTPUT>

</TABLE>

WolfShade
Legend
January 23, 2020

 

<CFOUTPUT QUERY="List" GROUP="AuthorID">
<!--- You should have something here for author, since you're grouping by author --->
    <TR>
<CFOUTPUT>
        <TD ALIGN="left" VALIGN="top" WIDTH="542" style="padding-left:2em;text-indent:-2em">
            <A HREF="#request.BaseURL#/book.cfm?-#URL_Title#-&BookID=#BookID#"><img src="#request.BaseURL#/images/#Image#" width="50"></A>
        </TD><cfif List.currentrow % 5 eq 0 AND List.currentrow neq List.recordCount>
    </tr>
    <tr>
</cfif>
</CFOUTPUT>
</TR>
</CFOUTPUT>

 

 

HTH,

 

^ _ ^