This topic is 4876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to create a somewhat dynamic site where content changes for every visit. I have a banner at the top which displays a couple links, and I'd like those to change-- not in a rolling series of ads kind of thing, but just different every time the page is loaded (or depending on the day of the week). At W3Schools, I found a script that allows me to list a few links, and one is picked at random during load. I can settle for that, but I'd rather have a table of links somewhere that I can edit independently (and possibly put other stuff to access like Flash ads and off-site links). Can anyone point me toward a tutorial that does this?

##### Share on other sites
Are you looking into server-side scripting (PHP/ASP) or into client-side scripting? If the latter then you're basically stuck with your list of links and pick one at random with javascript.

##### Share on other sites
Seeing as how the page will likely double as a login page for web-based software, server-side wouldn't be much of a departure.

##### Share on other sites
Well, assuming you use PHP (if not, it's almost identical in other languages) you would get something like this:
<?php$list = file_get_contents('/path/to/your/links.txt');$list = explode("\n", $list);$link = array_rand($list);echo '<a href="$link">$link</a>';?> Or, if you prefer a database (e.g. table "links" with fields "link" and "description"): <?php$conn = mysql_connect('localhost', 'username', 'password');mysql_select_db('database_name');$list = array();$i = 0;$result = mysql_query('SELECT * FROM links');while($row = mysql_fetch_assoc($result) ){$list[$i]['link'] =$row['link'];  $list[$i]['desc'] = $row['description'];$i++;}$link = array_rand($list);echo '<a href="$link[link]">$link[desc]</a>';mysql_free_result($result);mysql_close($conn);?>

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 37
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631413
• Total Posts
2999945
×