html code to display a random url from a database

Cpus

Senior member
Apr 20, 2012
345
0
0
Is there a simple way to write html code to display a random url from a database? Thanks.
 

Cpus

Senior member
Apr 20, 2012
345
0
0
I know how to create html code with a button that takes you to a specified url but I want th url to be random each time
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
I know how to create html code with a button that takes you to a specified url but I want th url to be random each time

How random do you want it to be? Each character random or a specific part of the URL to be random characters?
Is the possibility of getting an invalid return acceptable?

Otherwise, I would suspect that you have to create a list of valid URLs and then randomly choose one of them.
 

Unheard

Diamond Member
Jan 5, 2003
3,774
9
81
Since raw HTML doesn't have a good way of reading from a database, your best bet would be to put the values in XML format and access them via Javascript.

Take a look here: http://think2loud.com/224-reading-xml-with-jquery/

They have an example of using jQuery to read from an XML file. You would need to write the randomization on your own.
 

Cpus

Senior member
Apr 20, 2012
345
0
0
How random do you want it to be? Each character random or a specific part of the URL to be random characters?
Is the possibility of getting an invalid return acceptable?

Otherwise, I would suspect that you have to create a list of valid URLs and then randomly choose one of them.

yeah that is what i mean. a list of valid urls. I need to know how to get it to pick a random url from a database not just obe specified url.
 
Last edited:

clamum

Lifer
Feb 13, 2003
26,256
406
126
Seconded, my first thought was using JavaScript (or jQuery) to randomly access a list of URLs. I figured just an array but an XML file would be better, though I didn't realize jQuery could do that.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Load the url list of N items
Use a random method for your language to get an index from 0 to N-1
Get the url from the list position corresponding to the index.