Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


ASP image rotator on a timer looping through database records

Posted on 2009-04-11
Medium Priority
Last Modified: 2012-05-06
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.
Question by:meldraper
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
LVL 31

Expert Comment

by:Wayne Barron
ID: 24123971
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....


Author Comment

ID: 24124031
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.

Author Comment

ID: 24130158
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 31

Expert Comment

by:Wayne Barron
ID: 24131185
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.


Author Comment

ID: 24131207
Will do, and thanks again.  No big deal on the randomizer, either.

Author Comment

ID: 24347952
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.
LVL 31

Expert Comment

by:Wayne Barron
ID: 24349086
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.


Accepted Solution

meldraper earned 0 total points
ID: 24776673

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.

LVL 31

Expert Comment

by:Wayne Barron
ID: 24777686
Sounds good.
Good Luck with it.

Have a happy 4th of July.


Author Comment

ID: 24777696
You, too.  And just look at us, we are working!!
LVL 31

Expert Comment

by:Wayne Barron
ID: 24777751
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question