How to Display Images by Day of week
- Just a simple code to grab the image from a specfied folder without using any type of database
- Then Parse it to the page by day of the week having named each image by day and changing out by day
Ah, that won't work. That's because you are mixing 2 separate environments.
Javascript code runs on the client's browser, of which there could be millions. Whereas ColdFusion code runs on ColdFusion server, of which there is usually just one. In particular, the ColdFusion server know nothing of the Javascript code.
Those are the generalities. Now, on to the specifics to help you to get this to work.
From this code, I am assuming the following:
Here is some code that will do just that. It is 100% ColdFusion, involving no Javascript. 🙂
<body>
<!--- Query to fetch images and their properties --->
<cfquery name="rushedPics" datasource="myDSN">
select *
from myImgTBL
</cfquery>
<!---
Query of a query to fetch images whose name matches
today's name. There may be multiple images having a given
name.
--->
<cfquery name="rushed" dbtype="query">
select name
from rushedPics
where name like '#dateformat(now(), "dddd")#%'
</cfquery>
<cfset nrOfPics = rushed.recordcount>
<cfif nrOfPics gte 1>
<!--- Pick a random number between 1 and the total number of pictures--->
<cfset randNumber = randRange(1, nrOfPics, "SHA1PRNG")>
<!--- Relative path of randomly selected picture --->
<cfset relativePathImg = "votd/#rushed['name'][randNumber]#">
<!--- Display randomly selected picture --->
<cfoutput><img src="#relativePathImg#" width="150" height="113" border="0" alt=""></cfoutput>
</cfif>
</body>
Thanks for all the assistance I got it work now just added a table Named Banners into my own database for news etc..
Its just been awhile since I've coded in Cold Fusion
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.