Jump to content

Random HTML Code??


techiefreak05

Recommended Posts

You can do it with an array, or with a database.
Array way:
[code]<?php
//Create an array with the links
$links=array('<a href="www.domain1.com">domain1</a>','<a href="www.domain2.net">domain2</ a>');
$rand=array_rand($links); //pick a random link
echo $rand;
?>[/code]

The database way:
[code]<?php
//Let's say the table "links" has a column called "link" (values look like <a href...>...</ a>)
$sql="SELECT link FROM `links` ORDER BY RAND() LIMIT 1";
$result=mysql_query($sql);
$array=mysql_fetch_array($result);
echo $array['link'];
?>[/code]

Orio.
Link to comment
https://forums.phpfreaks.com/topic/16697-random-html-code/#findComment-70128
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.