Forum Moderators: open

Message Too Old, No Replies

Randomly Ordered ASP server side includes

         

indigojo

9:39 am on Oct 24, 2006 (gmt 0)

10+ Year Member



I have found some code that I need to modify to do what I need. Can someone tell me how I can change this code to bring in random SSI's (.ASP) rather than tables as below. Is this possible.

<%
Dim Quote(6)
Quote(0) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#FF4500'>&nbsp;</td></tr></table>"
Quote(1) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#336699'>&nbsp;</td></tr></table>"
Quote(2) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#111111'>&nbsp;</td></tr></table>"
Quote(3) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#556699'>&nbsp;</td></tr></table>"
Quote(4) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#999999'>&nbsp;</td></tr></table>"
Quote(5) = "<table width='90' border='1' cellspacing='0' cellpadding='0'><tr><td bgcolor='#444444'>&nbsp;</td></tr></table>"
QuoteList = ""
NumList = "¦"
Randomize
For x = 0 to 5
'get random number
RndQuote = Int(Rnd * 6)
Do Until Instr(Cstr(NumList),Cstr("¦" & RndQuote & "¦")) = 0
RndQuote = Int(Rnd * 6)
Loop
NumList = NumList & RndQuote & "¦"
QuoteList = QuoteList & Quote(RndQuote) & "¦"
Next
QuoteList = Left(QuoteList,Len(QuoteList)-1)
QuoteArr = Split(QuoteList,"¦")
For x = 0 to UBound(QuoteArr)
Response.Write QuoteArr(x)
Next
%>

mattur

9:53 am on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think you can use this method to choose a SSI file to include, because with ASP (unlike PHP) all SSI's are included before ASP processing begins.

You can certainly use a similar method to display random content in an ASP page, just not via selectively including SSI's. What's your aim here?

indigojo

10:10 am on Oct 24, 2006 (gmt 0)

10+ Year Member



My aim is to randomly display 6 graphics of equal size down one side of the page with each refresh creating a new order. I have found lots of info on random images but nothing that creates the same affect as the code above. I need to use ASP and I need to use SSI's. My current solition is hard to manage as it involves creating 5 different hard code pages with images manually shuffled and bringing them in like this.

<%
Randomize
RandNum = Int(Rnd * 6) + 1

if RandNum = 1 Then %>
<!--#include virtual="/Include/1.asp" -->
<% ElseIf RandNum = 2 Then %>
<!--#include virtual="/Include/2.asp" -->
<% ElseIf RandNum = 3 Then %>
<!--#include virtual="/Include/3.asp" -->
<% ElseIf RandNum = 4 Then %>
<!--#include virtual="/Include/4.asp" -->
<% ElseIf RandNum = 5 Then %>
<!--#include virtual="/Include/5.asp" -->
<% ElseIf RandNum = 6 Then %>
<!--#include virtual="/Include/6.asp" -->
<% End if %>

mattur

11:16 am on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note: I haven't checked the code initially posted, but you could possibly just replace the table code in each array element with your image markup. eg:

...
Quote(0) = "<img src=""myimage1.jpg"" ... >"
Quote(1) = "<img src=""myimage2.jpg"" ... >"
...

I don't think you need to use SSI's to achieve this, but you can do if required. Just remember, in ASP all the include files are included before processing starts. HTH

indigojo

11:57 am on Oct 24, 2006 (gmt 0)

10+ Year Member



thanks mattur, unfortunately i have to use SSI's as the advertising CMS outputs the code i need to use as SSI's. I can get this to work with jscript which is the other alternative for me to use but I do want the content visible to search engines.

defanjos

1:33 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe the following might work:

<%
RANDOMIZE
LowestNumber = 1
HighestNumber = 5
RandomNumber = INT((HighestNumber-LowestNumber+1)*Rnd+LowestNumber)

SELECT CASE RandomNumber
CASE "1"
%>
<!--#include virtual="/Include/1.asp" -->
<%CASE "2"%>
<!--#include virtual="/Include/2.asp" -->
<%CASE "3"%>
<!--#include virtual="/Include/3.asp" -->
<%CASE "4"%>
<!--#include virtual="/Include/4.asp" -->
<%CASE "5"%>
<!--#include virtual="/Include/5.asp" -->
<%END SELECT %>

mattur

3:05 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using the filesystemobject is your other choice, indigojo. You could read each SSI page using the filesystemobject into your array, then display as in msg#1. HTH

indigojo

6:29 pm on Oct 24, 2006 (gmt 0)

10+ Year Member



defanjos, that only brings in one SSI at a time. I need to bring in all 6 at the same time and re-arrange their order of apperance each time so i end up with an out put that looks like this on page

<!--#include virtual="/Include/3.asp" -->
<!--#include virtual="/Include/2.asp" -->
<!--#include virtual="/Include/1.asp" -->
<!--#include virtual="/Include/6.asp" -->
<!--#include virtual="/Include/4.asp" -->
<!--#include virtual="/Include/5.asp" -->

and next time

<!--#include virtual="/Include/5.asp" -->
<!--#include virtual="/Include/2.asp" -->
<!--#include virtual="/Include/6.asp" -->
<!--#include virtual="/Include/3.asp" -->
<!--#include virtual="/Include/4.asp" -->
<!--#include virtual="/Include/1.asp" -->

etc

Mattur can you go a little further on what you mean by uinsg filsystemobject?

defanjos

7:17 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



oops, sorry.
I misunderstood you.

indigojo

7:46 pm on Oct 24, 2006 (gmt 0)

10+ Year Member



Basically I'm after a more elegant way to do this (below) which automates the shuffle rather than me hard coding the order in like this.

<%
RANDOMIZE
LowestNumber = 1
HighestNumber = 2
RandomNumber = INT((HighestNumber-LowestNumber+1)*Rnd+LowestNumber)

SELECT CASE RandomNumber
CASE "1"
%>
<!-- #include virtual="ads/1.asp" -->
<!-- #include virtual="ads/2.asp" -->
<!-- #include virtual="ads/3.asp" -->
<!-- #include virtual="ads/4.asp" -->
<!-- #include virtual="ads/5.asp" -->
<%CASE "2"%>
<!-- #include virtual="ads/5.asp" -->
<!-- #include virtual="ads/4.asp" -->
<!-- #include virtual="ads/5.asp" -->
<!-- #include virtual="ads/1.asp" -->
<!-- #include virtual="ads/2.asp" -->
etc...
<%END SELECT %>

mattur

8:06 am on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The filesystemobject can be used in ASP to perform file operations including reading the content of a file. Here's a simple function to return the content of a file, when supplied with a filesystem path:

'---------------------------------------------------
Function GetTextFileContent(strPath)

Const ForReading = 1

Dim fso, fil, txs, varFileContent

'setup filesystemobject and file objects
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fil = fso.GetFile(strPath)

'open textstream
Set txs = fil.OpenAsTextStream(ForReading)

'read file, return null if blank
If Not txs.AtEndOfStream Then
varFileContent = txs.ReadAll
Else
varFileContent = Null
End If

txs.Close
Set txs = Nothing
Set fil = Nothing
Set fso = Nothing

GetTextFileContent = varFileContent

End Function
'---------------------------------------------------

You could use it to read each include file, something like:

Quote(0) = GetTextFileContent(Server.MapPath("/") & "/ads/1.asp")
... etc

You could speed up the script by re-writing the function to loop thru and read each include file and return an array of ads, so you only have instantiate the filesystemobject once.