Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotating Include Files/ Is it possible with Javascript/ASP 3

Status
Not open for further replies.

Tread42

MIS
Feb 5, 2002
151
US
I have a main page that is composed of several include files. I want to rotate an ad that is composed in a table dynamiclly on each load. Very similar to a picture rotator, but this would call the include file, which contains this ad's table. So for instance: One time the page loads with this code in the body: <!-- #include virtual=&quot;/03_includes/ads1.asp&quot; -->Then next time it might be ad2.asp through how ever many ads are currently running. I can't seem to get this to work.

Anyone out there have any ideas or faced similar challenges. Maybe the problem isn't that this won't work, but that I'm not seeing a better way to do the ASP code from scratch. The files ad1.asp contain nothing more than the raw table and images for the ads. (Each ad is sliced into several sections and links to unique places.)



Regards,
Tread42
 
Read this post

thread333-670076

Might be easier using simple javaScript rather than includes....

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Hi,

SSI is very limited, unfortunatly. You've seen the FAQ on &quot;random content&quot;.
The code there only simulates a random script. It should actually work for you but it will never rotate in order and it will never be truly random, it is dependant entirely on the time the page is loaded.

If you want to use the FAQ code, i just tested it to double-check and it works fine. It will load a different ad for you based on the time the page is called.
But remember if you have 5 ads and only code it for 5 seconds then 1 ad could potentially be displayed for 92% of the time.
The second set of code in the FAQ would be good if you have up to 10 ads, it should work find then.

Assuming the code isn't working for you, what exactly is the problem? The exact same ad gets displayed everytime?
Do you understand the way the code works?





<!--#sig value=''É'' url='' -->
 
Thanks Cian for responding. I believe I understand how the code works. But I've tried editing it like this: <!--#config timefmt=&quot;%S&quot; -->
<!--#set var=&quot;rand&quot; value=&quot;$DATE_LOCAL&quot; -->
<!--#if expr=&quot;$rand = /.0/&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#elif expr=&quot;$rand = /.1/&quot; -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#elif expr=&quot;$rand = /.2/&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#elif expr=&quot;$rand = /.3/&quot; -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#elif expr=&quot;$rand = /.4/&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#elif expr=&quot;$rand = /.5/&quot; -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#elif expr=&quot;$rand = /.6/&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#elif expr=&quot;$rand = /.7/&quot; -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#elif expr=&quot;$rand = /.8/&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#elif expr=&quot;$rand = /.9/&quot; -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#else -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#endif -->

With only 2 ads, using all of these lines? Or just the first two?

Regards,
Tread42
 
I copied and pasted the code as you posted it and it works.

Every 10, 20, 30, 40, 50, 60, 12, 22, 32, 42, 52 seconds (etc etc as per the code shows) ad 1 gets shown and the rest of the time ad2 gets shown.
So if you keep refreshing your page you will see the ad changing all the time.

Because you only have 2 ads you can simplify the code using AND OR operators, basic info here:


Is this what you require from the code or is there something more? As I said SSI is very limited, it was never intended for this but will work fine if you only require basic functionality.




<!--#sig value=''É'' url='' -->
 
Sorry I didnt really read the post and missed your last question.

No you can simplify the code because u have only 2 ads,
just tested the following:

<!--#config timefmt=&quot;%S&quot; -->
<!--#set var=&quot;rand&quot; value=&quot;$DATE_LOCAL&quot; -->
<!--#if expr=&quot;($rand = /.0/) || ($rand = /.2/) || ($rand = /.4/) || ($rand = /.6/) || ($rand = /.8/)&quot; -->
<!--#include virtual=&quot;/03_includes/ad1.asp&quot; -->
<!--#else -->
<!--#include virtual=&quot;/03_includes/ad2.asp&quot; -->
<!--#endif -->





<!--#sig value=''É'' url='' -->
 
For some reason it always loads both on top of each other. Even after the most recent code changes.
Could this be because I'm using mutling SSI's on this page. All header/footer info are located in different SSI's as well as the side ads.

I'm kind of baffled at why it repeats the side navigation and everything over.

I was wanting it to display just the first ad under the text &quot;sample rotator goes here&quot; then the second ad if it happens to hit at the right second.

I'm sure it's an easy fix and sorry to ask so many questions. I do truly appreciate all the help.

Regards,
Tread42
 
which is the part of your page getting screwed up? You have two navigation column2, i presume the second one shouldn't be there? (below the rotator)
Have you tested the script in a page on it's own?




<!--#sig value=''É'' url='' -->
 
I'll test on a page of it's own.

Other than the header/footer the entire page is repeating. The left hand nav, the right hand ads. All I want is it to look similar to this: but only display one ad instead of both. And then rotate the ads out for another at a given time.

Did I mis-interpret the code?

Regards,
Tread42
 
We're almost posting at the same time so it's getting confusing.
I use multiple SSI code blocks on my pages for headers, footers etc and many nested SSI's and they never cause problems, if they work individually there shouldn't be a problem.

You're ad2 is significantly different than ad1, could this be a problem? Ad2 also includes the navigation column as well as 2 other ads whereas ad1 is only the ad image.

I think you need to strip back the code a bit, there's likely a mistake which is causing the problem.




<!--#sig value=''É'' url='' -->
 
This is a test of the code I last posted:


It works here ok so there must be something in the page causing interference.

Have to go home now but will be online tomorrow if you are still stuck. Perhaps there's others who can help also??





<!--#sig value=''É'' url='' -->
 
I see what you are saying and I see it working on yours.

However, when I strip out the code and place it in it's own page, I still get the error.
I wonder if it's not calculating the server time correctly or something? I

Regards,
Tread42
 
Just echo the time (with SSI) in seconds and see what is the output.
It could also be the operators, my server couldn't handle some operators (for reasons unknown) before they upgraded.





<!--#sig value=''É'' url='' -->
 
I think you should consider taking a completely different approach. It doesn't make any sense to me to be coding the selection of ads into the SSI on each page. What happens when you add a new ad? You have to go and re-code each page to include the new choice.

What you should be putting is an SSI command to say &quot;advert goes here&quot; and leave the script to pick which one. So your SSI would just be
[tt]
<!--#include virtual=&quot;/03_includes/ad.asp&quot; -->
[/tt]
and [tt]ad.asp[/tt] would do all the work of picking an advert (at random, in sequence, whatever) and displaying it.

Sometimes the best answer is to change the question!

-- Chris Hunt
 
Good posts cian - unfortunately you ssi-developer.net links aren't working right now (6:30 AM EST 10/31/2003) - but it looks like I need to read 'em all so I can get a handle on them. I've never used SSI

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks wolf00. Some server problems today, should be working now.

Chris, if it's going on every page then you'd just put the ad script another file and call that file with an include. :)
So it's the same as calling an asp script really, difference is that it's probably easier to do in SSI but easier on the server in asp, i think.





<!--#sig value=''É'' url='' -->
 
p.s. I used something similar for my site logo, rather than simulate a random change, the logo changed on specific days. And that script had to go into 75 pages, worked no problem and I only needed to edit that one source file.





<!--#sig value=''É'' url='' -->
 
since you are only utilizing two &quot;variables&quot; .. basically, odd/even, why not just generate a random number and check odd/even status and include appropriately?

if you have more ads (say, 3), why not just generate a random number between 1-3 and include the appropriate ad file?

since you are obviously using ASP, why not just have ASP generate the number and then the include?

<%@ Language = VBScript %>
<% Response.Buffer=True %>
<%
Dim Value
Randomize
Value = Int((3 * Rnd) + 1)

if Value = 1 then
%>
<!--#include virtual=&quot;/ad1.asp&quot;-->
<%
elseif Value = 2 then
%>
<!--#include virtual=&quot;/ad2.asp&quot;-->
<%
elseif Value = 3 then
%>
<!--#include virtual=&quot;/ad3.asp&quot;-->
<%
end if
%>

Or, if you wish to shorten that code, you can even do something like:

<%@ Language = VBScript %>
<% Response.Buffer=True %>
<%
Dim Value
Randomize
Value = Int((3 * Rnd) + 1)
strIncludeFile = &quot;/ad&quot; & Value & &quot;.asp&quot;
Server.Execute(strIncludeFile)
%>

Just another option.
 
Tony/Cian:

Thank you for all your help. Tony I am currently using your suggestion. I appreciate all the time and effort of you and all of those like you who make this board a great resource.

Thanks again
Tread42

Regards,
Tread42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top