Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • 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.
0
meldraper
Asked:
meldraper
  • 6
  • 5
1 Solution
 
Wayne BarronCommented:
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
 
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.
0
 
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.

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Wayne BarronCommented:
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
 
meldraperAuthor Commented:
Will do, and thanks again.  No big deal on the randomizer, either.
0
 
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.
0
 
Wayne BarronCommented:
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
 
meldraperAuthor Commented:
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
 
Wayne BarronCommented:
Sounds good.
Good Luck with it.

Have a happy 4th of July.

Carrzkiss
0
 
meldraperAuthor Commented:
You, too.  And just look at us, we are working!!
0
 
Wayne BarronCommented:
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

Independent Software Vendors: 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!

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