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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display images based on a query

Status
Not open for further replies.

akalinowski

IS-IT--Management
Oct 3, 2006
190
US
i have a set of product images i want to display in a page
i only want 4 columns and 3 rows of images and have it page
however i am lost on where to get started

the product_id will be the same as the image name so produtct id ts132 will be ts123.jpg so i can use img src=/images/#prodid#.jpg i got that far but formating it i'm lost.

akalinowski
 
Are you familiar with the basics of html?

<cfset prodid = "ts123">

<cfoutput>
<img src="/images/#prodid#.jpg">
</cfoutput>

If you can't stand behind your troops, stand in front of them.
Semper Fidelis

Jim
 
i know how to list just one image and html i got down, but i didnt understand cfloop yet
here is the code that did it...


<table >
<cfloop query = "qry_products">
<cfif CurrentRow MOD 7 IS 1><tr></cfif>
<td>
<cfoutput><a href="whatever"><img src="#product_id#_thumb.jpg"><br/>
#Product_Name#</cfoutput></a>
</td>
<cfif CurrentRow MOD 7 IS 0>
</tr>
</cfif>
</cfloop>
</table>


akalinowski
 
also went one step further

and did this...
Code:
<table > <cfloop query = "qry_products"> 
<cfif CurrentRow MOD 7 IS 1>
<tr></cfif>
<td><cfoutput>
<a href="/product.cfm?product_id=#product_id#">
<cfif fileexists "C:\webroot\images\#product_id#.jpg>
<img src="/images/#product_id#_thumb.jpg" alt="#product_description#>
<cfelse>
<img src="/images/no_pic.jpg" alt=" sorry no pic for #product_description#>
</cfif>
<br/>#Product_Name#

</cfoutput></a> </td> <cfif CurrentRow MOD 7 IS 0> </tr>   </cfif> </cfloop> </table>

akalinowski
[URL unfurl="true"]www.olivelabs.com[/URL]
 
Don't forget to close [/code] the code tag. Notice the "structure" of my example? If your going to write code then an indentation policy is crucial for debugging.

I don't see a need for <cfloop> here.

look this over
Code:
<table>
 <cfoutput query="qry_products">
  <cfif qry_products.CurrentRow MOD 3 eq 1>
   <tr>
  </cfif>
  <td>
    <cfif fileexists("C:\webroot\images\#qry_products.product_id#.jpg")>
	 <a href="/product.cfm?product_id=#qry_products.product_id#" target="_blank"> 
      <img src="/images/#product_id#_thumb.jpg" alt="#qry_products.product_description#>
	 </a>
    <cfelse>
     <img src="/images/no_pic.jpg" alt=" sorry no pic for #qry_products.product_description#">
    </cfif>
    <br/>#qry_products.Product_Name#
  </td>
  <cfif qry_products.CurrentRow MOD 3 eq 0>
   </tr>
  </cfif>
 </cfoutput>
</table>



Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
And in the interest of well-formed HTML, make sure you fill out the table correctly after the recordset is done.

For instance, in Lyndon's code example, let's say the query returned 10 records. So the tenth image displays in the first column of the fourth row. Now, you drop out of the CFOUTPUT because there are no more records. Unfortunately, since currentrow mod 3 is not 0, you haven't completed the <td> and <tr> tags for that row.



-------++NO CARRIER++-------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top