Link to home
Start Free TrialLog in
Avatar of nick_harambee
nick_harambee

asked on

i need some help to change this code which generates a table of thumbnails.

hello,

dldeeds kindly posted some coldfusion code which generates a table of thumbnails which each have a link to a html page.  here is the code which i have adapted slightly for my purposes:

<cfdirectory directory="C:\CFusionMX\wwwroot\thumbnails\psychotherapists"
      action="list"
      name="images"
      filter="*.jpg"
      sort="name ASC">

<!--- Set a counter to 0 and a var to hold the total number of images  --->
<cfset numrec=images.RecordCount>
<cfset s=0>
<style type="text/css">
<!--
body {
      background-color: #EDEAE4;
}
.style3 {font-size: x-small}
.style5 {font-size: 9px}
.style6 {font-size: larger}
.style8 {color: #666600}
.style9 {font-size: xx-large}
.style11 {font-size: xx-large; color: #666666; }
-->
</style>
<title>psychotherapists</title><table width="100%" border="0">
<tr><td colspan="8" align="center" class="style9">
  <p class="style8">Psychotherapists</p></td>
</tr>
<span class="style5">
<!--- Title row --->
</span><span class="style5">
<cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span><span class="style6">
<cfloop query=images>
</cfloop>
</span><span class="style5"><cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span><span class="style3"><cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span>
<cfloop query=images>
  <!--- Create a variable to contain each Authors page (authorname.htm) --->
  <cfset AuthorPage=ReplaceNoCase(images.name, ".jpg", ".htm")>
  <!--- Create a variable to contain the Authors name to use under the image      --->
  <cfset AuthorName=ReplaceNoCase(images.name, ".jpg", "")>
  <cfset s=s+1>
   <!--- use modulus function to know when to change rows - this one is set up for 3 images per row --->
  <cfset mods=(s mod 8)>
  <cfoutput>
  <cfif mods eq 1>
     <tr>
  </cfif>
  <!--- Create a table cell for each image in the query --->
  <!--- Each cell will contain the thumbnail which is also a link to the author page, with authors name under thumbnail --->
   <td width="12%" td align="center" valign="top">
   <A href="/psychotherapists/#AuthorPage#"><img src="/thumbnails/psychotherapists/#images.name#" alt="thumbnail image"  border="0"></A>
   <br>
   <span class="style8">#AuthorName#</span>
   </td>
   <cfif mods eq 0>
   </tr>
   </cfif>
   <!--- If we are on the last image from the query, close the row if it has not been, then close the table  --->          
   <cfif s eq numrec>
   <cfif mods neq 0>
   </tr>
</cfif>
</table>
</cfif>
</cfoutput>
</cfloop>

i would like to make 2 changes to this code:

(i) firstly, rather simply, i would like there to be a one line space between the title 'psychotherapists' and the table itself.  i have tried putting a line break in various places, but can't get it to work.

(ii) at the moment the code sorts the thumbnails alphabetically according to the first name of the psychotherapists.  i would like the text under the therapists to include the first name and to read, e.g. as 'sigmund freud' (which it does at present), but i would like to sort the thumbnails according to the surname, i.e. 'freud'.  would it be possible to adapt the code to do this?

thanks

nick
Avatar of sigmacon
sigmacon

1) <title> is not valid in a body tag, it needs to between <header> tags - so should you style definition. Then, instead you can do:
2) <h1>psychotherapists</h1><table width="100%" border="0"> ... <!--- this should put enough space between the table and the headline --->
3) This entire piece of code doesn't seem to have any function and <span> is not allowed here anyway - you may want to delete all of it:

<span class="style5">
<!--- Title row --->
</span><span class="style5">
<cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span><span class="style6">
<cfloop query=images>
</cfloop>
</span><span class="style5"><cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span><span class="style3"><cfloop query=images>
</cfloop>
<cfloop query=images>
</cfloop>
</span>

4) After your (updated) directory listing,

<cfdirectory directory="C:\CFusionMX\wwwroot\thumbnails\psychotherapists"
      action="list"
      name="imagesOrig"
      filter="*.jpg"
      sort="name ASC">

insert this code:

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

<cfset QueryAddColumn(imagesOrig, LastName)>
<cfloop query="imagesOrig">
    <cfset QuerySetCell(imagesOrig, "LastName", ListLast(ReplaceNoCase(name, ".jpg", ""), " "), CurrentRow)
</cfloop>

<cfquery name="images" dbtype="query">
    select *
    from imagesOrig
    order by LastName
</cfquery>

----------------------------
Avatar of nick_harambee

ASKER

having changed the code as you suggested i get the following error message:

 Invalid CFML construct found on line 10 at column 1.
ColdFusion was looking at the following text:

</

The CFML compiler was processing:

    * a cfset tag beginning on line 9, column 6.
    * a cfset tag beginning on line 9, column 6.

 
The Error Occurred in C:\CFusionMX\wwwroot\psychotherapists1.cfm: line 10

8 : <cfloop query="imagesOrig">
9 :     <cfset QuerySetCell(imagesOrig, "LastName", ListLast(ReplaceNoCase(name, ".jpg", ""), " "), CurrentRow)
10 : </cfloop>
11 :
12 : <cfquery name="images" dbtype="query">
Nick, sorry about that, I cannot test this code because I don't have the image names. I forgot a closing > ... this is a kind of error you should be able to fix yourself:

<cfset QuerySetCell(imagesOrig, "LastName", ListLast(ReplaceNoCase(name, ".jpg", ""), " "), CurrentRow)>
thanks sigmacon

now i get this error message:

 Parameter validation error for function QUERYADDCOLUMN.
The function takes 3 parameters.
 
The Error Occurred in C:\CFusionMX\wwwroot\psychotherapists.cfm: line 7

5 :       sort="name ASC">
6 :         
7 : <cfset QueryAddColumn(imagesOrig, LastName)>
8 : <cfloop query="imagesOrig">
9 :     <cfset QuerySetCell(imagesOrig, "LastName", ListLast(ReplaceNoCase(name, ".jpg", ""), " "), CurrentRow)>

nick.
ASKER CERTIFIED SOLUTION
Avatar of sigmacon
sigmacon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
now i get this error message:

 Variable IMAGESORIG is undefined.
 
The Error Occurred in C:\CFusionMX\wwwroot\psychotherapists.cfm: line 7

5 :       sort="name ASC">
6 :         
7 : <cfset QueryAddColumn(imagesOrig, 'LastName', arrayNew(1))>
8 : <cfloop query="imagesOrig">
9 :     <cfset QuerySetCell(imagesOrig, "LastName", ListLast(ReplaceNoCase(name, ".jpg", ""), " "), CurrentRow)>

Please refer to my earlier comment - I renamed the query in the directory listing so we didn't have to rename so much further down the road:

4) After your (updated) directory listing,

<cfdirectory directory="C:\CFusionMX\wwwroot\thumbnails\psychotherapists"
      action="list"
      name="imagesOrig"
      filter="*.jpg"
      sort="name ASC">
thanks a lot sigmacon

this works fine now

nick.