Help with basic code
Posted: Mon Jul 07, 2003 7:51 am
I'm calling this basic php code to rotate 3 image links 'randomly' on page refresh.
Is there anyone who can see how to amend my code to simply rotate these links in 'order' rather than 'randomly'.
I struggle with PHP code, and all my editing so far has failed to get it right.
Any help or advice is very much appreciated.
TIA
<?php
$Ad[0] = '<a href="link1" id="link1"><img src="1.gif" width="468" height="60" border="0" id="link_1" /></a>';
$Ad[1] = '<a href="link2" id="link2"><img src="2.gif" width="468" height="60" border="0" id="link_2" /></a>';
$Ad[2] = '<a href="link3" id="link3"><img src="3.gif" width="468" height="60" border="0" id="link_3" /></a>';
$Weight[0]=1;
$Weight[1]=2;
$Weight[2]=3;
$Weight[3]=0;
$sum =0;
for($i=0;$i<count($Weight);$i++)
$sum+=$Weight[$i];
$ShowAd = rand(0, $sum - 1);
for($i=0;$i<count($Weight);$i++)
{
if($ShowAd<=$Weight[$i])
{
$ShowAd=$i;
break;
}
else
$ShowAd-=$Weight[$i];
}
echo $Ad[$ShowAd];
?>
Is there anyone who can see how to amend my code to simply rotate these links in 'order' rather than 'randomly'.
I struggle with PHP code, and all my editing so far has failed to get it right.
Any help or advice is very much appreciated.
TIA
<?php
$Ad[0] = '<a href="link1" id="link1"><img src="1.gif" width="468" height="60" border="0" id="link_1" /></a>';
$Ad[1] = '<a href="link2" id="link2"><img src="2.gif" width="468" height="60" border="0" id="link_2" /></a>';
$Ad[2] = '<a href="link3" id="link3"><img src="3.gif" width="468" height="60" border="0" id="link_3" /></a>';
$Weight[0]=1;
$Weight[1]=2;
$Weight[2]=3;
$Weight[3]=0;
$sum =0;
for($i=0;$i<count($Weight);$i++)
$sum+=$Weight[$i];
$ShowAd = rand(0, $sum - 1);
for($i=0;$i<count($Weight);$i++)
{
if($ShowAd<=$Weight[$i])
{
$ShowAd=$i;
break;
}
else
$ShowAd-=$Weight[$i];
}
echo $Ad[$ShowAd];
?>