Random rotation banner script
Moderator: General Moderators
Random rotation banner script
Can someone point me in the direction to find a rotating banner script? Or paste the code here?
I need to rotation script to randomly sort 3 or 4 text files when the page gets refreshed.
Any ideas?
I need to rotation script to randomly sort 3 or 4 text files when the page gets refreshed.
Any ideas?
I use this for my banner add rotation.
Now I am showing a graphic but you could easily adapt that to show a text file. This script is pulling from a database but a hard coded array would work as well.
Code: Select all
<?php
$sqlquery = "SELECT * From banners where active='Y' ORDER BY RAND() LIMIT 1";
$result=mysql_query($sqlquery);
$bid=mysql_result($result,0,'bid');
$image=mysql_result($result,0,'image');
$sql=("update banners set views=views+1 where bid='$bid'");
$result2=mysql_query($sql);
echo "<a href="http://www.domain.com/banners/banners.php?bid=$bid" target="_blank">
<img src="http://www.coastgames.com/banners/images/$image" border="0"></a>";
?>Okay. lets say you have the names of the text files in a database. As that is what I have. Then you could have something like this.
First line pulls out a random text file. Last line prints it to the screen.
Code: Select all
<?php
$sqlquery = "SELECT * From banners where active='Y' ORDER BY RAND() LIMIT 1";
$result=mysql_query($sqlquery);
$bid=mysql_result($result,0,'bid');
$text=mysql_result($result,0,'text');
$sql=("update banners set views=views+1 where bid='$bid'");
$result2=mysql_query($sql);
echo $text;
?>instead of randomizing the array, call a part fo the array at random......
$link=$link_array[rand(0, (count($link_array)-1))];
randomly giving you an element within the array (note, count()-1 used because count gives you the number of elements, the highest number that wont give an error is count-1 since arrays start counting at 0)
$link=$link_array[rand(0, (count($link_array)-1))];
randomly giving you an element within the array (note, count()-1 used because count gives you the number of elements, the highest number that wont give an error is count-1 since arrays start counting at 0)
Thanks for the script m3rajk.
I am getting an error though...
Parse error: parse error in /home/u5/franchise/html/rhcol/rh-sponsors-default.php on line 13
Can anyone see my mistake. I am sure it is obvious to you pro's.
I am getting an error though...
Parse error: parse error in /home/u5/franchise/html/rhcol/rh-sponsors-default.php on line 13
Can anyone see my mistake. I am sure it is obvious to you pro's.
Code: Select all
<?php
$sponsor=randSponsor();
funtion randSponsor(){
$spon=array('sponsor-80.txt', 'sponsor-115.txt', 'sponsor-300.txt');
$randspon=$spon[rand(0, (count($spon)-1))];
return $randspon;
}
?>funtion should be function, but that could just be in typing it up here....
if line 13 is the line $randspon is set, then it could be getting the random number. so if that's 13, try replacing it with
if line 13 is the line $randspon is set, then it could be getting the random number. so if that's 13, try replacing it with
Code: Select all
$randIndex=rand(0, (count($spon)-1));
$randspon=$spon[$randIndex];