Show random links from db

They have: 4 posts

Joined: Sep 2001

Hi!

I´m in need of a script that shows several random links from a database, anyone that can help me?

I have a database that contains about 400 different links, I would like to show 10 of them on my website, in random order so if I reload 10 new links will show.

Thans in advance. Laughing out loud

/Plutt

They have: 4 posts

Joined: Sep 2001

..sorry, forgott to say that it´s ASP.

They have: 4 posts

Joined: Sep 2001

I have tried Hotscripts already.. no luck... Sad
Do ya have any other tips?

/Plutt

Keegan's picture

They have: 300 posts

Joined: Aug 2001

This looks like a very good start for you.

http://www.web-savant.com/users/kathi/asp/start.html

They have: 4 posts

Joined: Sep 2001

hehe, I work as a application developer so I know ASP.. Wink
I just cant get it to work, thats why I´m in need of help.

This is my code so far:

<?php
Dim counter
,i,found, links(5), link

Set databas
= Server.CreateObject("ADODB.Connection")
databas.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="& Server.MapPath("test.mdb")
SQL = "select count(t1) AS count_lankar from tester"
Set RS_count_lankar = databas.Execute(SQL)

Randomize
counter
= 0
do
   
link = Int(rnd*RS_count_lankar("count_lankar")) - 1
    found
= 0

       
for i = 0 to counter - 1
           
if links(i) = link then
            found
= 1
           
exit for
           
end if
       
next

   
if found = 0 then
    links
(counter) = link
    counter
= counter -- 1
    end
if


    if
counter = 6 then
   
exit do
   
end if

loop



SQL
= "Select t1 from tester"
Set RSdbase = Server.CreateObject("ADODB.Recordset")
RSdbase.open SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="& Server.MapPath("test.mdb"), adLockPessimistic, adOpenKeyset

for i = 0 to 5
    RSdbase
.movefirst
    response
.write i & ":" & links(i) & "<br>"
   
RSdbase.Move links(i)
   
Response.Write RSdbase("t1")
next

RS_count_lankar
.Close
Set RS_count_lankar
= Nothing

RSdbase
.Close
Set RSdbase
= Nothing

databas
.Close
Set databas
= Nothing
?>

But the errormessage tells me that the db is EOF.. wich is strange..

Keegan's picture

They have: 300 posts

Joined: Aug 2001

Someone will be able to help you.

I dont know ASP, good luck.

K

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.