• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

ASP image rotator on a timer looping through database records

I've searched for the answer but it's a hard one to search for.  I need an image rotator that will loop through my database of images, display and automatically change every five seconds or so.  My folder name is rotator/prizes and the images are uploaded through a content editor and the names are stored in an access database.  A javascript/ASP solution would be ideal.  I'm better at ASP than Javascript.  Any thoughts will be greatly appreciated.  Thanks in advance.
  • 6
  • 5
1 Solution
Wayne BarronAuthor, Web DeveloperCommented:
not sure but, in order for you to do something like that you would need to have it done
In a FRAME (or) IFRAME. ( I would think )

You can set it up to Refresh every so many seconds.
And use this code that I made up for another user


The only think that you would need to add in a
<meta refresh>
For 5 seconds.

Let me know if this is something that you would like to have.
And I will help you to add in the refresher....

meldraperAuthor Commented:
I LOVE IT.  Let me mess around with it for a while and maybe I can figure out the refresh myself.  Many thanks for this.  I really appreciate it.  I will let you know either way.
meldraperAuthor Commented:
Hi Carrzkiss, I worked with the script and I have a few quesitons.  I notice that "undefined" comes up a lot.  I have three images.  I set line 36 to 4 instead of 59 since I didn't have that many.  I put the refresh code in for every 5 seconds.  Take a look at this and help me figure out what I'm doing wrong.  Also, is there a way for it not to randomize?  Many thanks.


<meta HTTP-EQUIV="Refresh" CONTENT="5; url=1.asp">
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("Q_24265323.mdb") & ";"
getS = Request.QueryString("ID")
Set objRs=Server.CreateObject("ADODB.RecordSet")
getSQL = "select id, FileName, ImageTitle FROM ImageTable ORDER BY ID ASC"
objRs.Open getSQL, objConn, 1, 1, 1
<style type="text/css">
border: 1px solid #000;
<script type="text/javascript">
//The array which is going to hold the image information. Store the image info along with their correct path; I've omitted the path here as I've stored the images in the same folder where my web page resides.
var imageArray = new Array();
var imageID = new Array();
var imageTitle = new Array();
 <%While Not objRs.EOF%> 
imageArray[<%=objRs("id")%>] = "images/<%=objRs("FileName")%>"; 
imageID[<%=objRs("id")%>] = "<%=objRs("id")%>";
imageTitle[<%=objRs("id")%>] = "<%=objRs("ImageTitle")%>";
function doIt()
var rand = Math.floor(Math.random()*4); //we have 58 images in the database, so we set the # to 59
var imgPath = "<a href='"+imageArray[rand]+"' target='_blank'><img src='"+imageArray[rand]+"' alt='"+imageArray[rand]+"' border='0' align='absmiddle' width='400' height='285' /></a>";
var imgID = "Image ID is: "+imageID[rand]+". <a href='javascript:history.go(0)'>Refresh page</a><br />"
var imgTit = ""+imageTitle[rand]+""
document.getElementById("image").innerHTML = imgPath;
document.getElementById("imageID").innerHTML = imgID;
document.getElementById("imageTitle").innerHTML = imgTit; 
Click image to see it's actual size<br/>
<div id="image" style="width:400px;"></div>
<div id="imageID"></div>
<div id="imageTitle"></div>
<script type="text/javascript">
    Set objRs=Nothing

Open in new window

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Wayne BarronAuthor, Web DeveloperCommented:
there is no way to not randomize. Unfortunantly.

In my demo, I found the same issue of: undefined.
Once it got past the amount of images that was listed in the database.
I changed the # to the exact number of images in the database, and that fixed it in my Demo.
BUT, When I changed the # from 4 - to - 3
In your demo, it still showed me the same error.

Right now, I am unsure as to why it is doing it on yours and not with mine.

With mine, I am thinking that setting to 59 when there is 58 records in the database, would cause this issue.

See, this script was not like this when I found it, I changed it to work with a Database.
So, I am unsure as how to fix it?

I will do some more checking on this later on today, as I am getting ready to leave for a while.

Change your # from 4 to 3
And play around with it, and see what you can find out.

meldraperAuthor Commented:
Will do, and thanks again.  No big deal on the randomizer, either.
meldraperAuthor Commented:
carrzkiss, I was not able to use this because of the "undefined" thing, so I'm going to just delete the question.  I'll have to figure out another way.  Please reply so I can either delete the question or work with another fix you might have.  Many thanks.
Wayne BarronAuthor, Web DeveloperCommented:
Instead of deleting, lets look at a few other codes here.

This is an ASP Image Rotator.
Use it in the same way that you did mine, with the page refreshing every how often you desire.

See if it will work for you.
Look pretty nice.

meldraperAuthor Commented:

I'm going to use Flash with an XML backend instead.  I can programmatically manipulate the XML file.  Thank you very much for your help, though.

Wayne BarronAuthor, Web DeveloperCommented:
Sounds good.
Good Luck with it.

Have a happy 4th of July.

meldraperAuthor Commented:
You, too.  And just look at us, we are working!!
Wayne BarronAuthor, Web DeveloperCommented:
I have to release my new site on Monday, so I will most likely work through-out the day.
I have my son right beside me on the other Computer chatting with friends.
So, that is good enough for me.
Next year will be a better time to celebrate, not right now, to much to do.

Good Luck
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now