Solved

ASP image rotator on a timer looping through database records

Posted on 2009-04-11
11
476 Views
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.
0
Comment
Question by:meldraper
  • 6
  • 5
11 Comments
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
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 )

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

http://ee.cffcs.com/Q_24265323/1.asp
http://ee.cffcs.com/Q_24265323/Q_24265323.zip

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....

Carrzkiss
0
 

Author Comment

by:meldraper
Comment Utility
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.
0
 

Author Comment

by:meldraper
Comment Utility
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.

http://weddingfairshow.com/untitled/1.asp


<html>

<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") & ";"

objConn.Open

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">

#image

{

border: 1px solid #000;

}

 

</style>

<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")%>";

<%

 objRs.MoveNext

    Wend

%>

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; 

}

</script>

</head>

 

<body>

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">

doIt();

</script>
 

</body>

</html>

<%

    objRs.Close

    Set objRs=Nothing

%>

Open in new window

0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
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.

Carrzkiss
0
 

Author Comment

by:meldraper
Comment Utility
Will do, and thanks again.  No big deal on the randomizer, either.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:meldraper
Comment Utility
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.
0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
Instead of deleting, lets look at a few other codes here.

http://weblog.sitepros.net/journal_comments.asp?JournalID=79
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.

Carrzkiss
0
 

Accepted Solution

by:
meldraper earned 0 total points
Comment Utility
Carrzkiss,

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.

Melissa
0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
Sounds good.
Good Luck with it.

Have a happy 4th of July.

Carrzkiss
0
 

Author Comment

by:meldraper
Comment Utility
You, too.  And just look at us, we are working!!
0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
Yep.
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
Carrzkiss
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now