Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

banner rotation script 3

Status
Not open for further replies.

brownfox

Programmer
Joined
Jan 5, 2003
Messages
173
Location
GB
I've written this simple daily banner rotation script, it works OK but I'm sure it's a bit clumsy and can be done a lot simpler. Has anyone got any suggestions to clean it up?
<?
$date_time_array = getdate (time());
$banner_array = array(&quot;banner1.gif&quot;,&quot;banner2.gif&quot;,&quot;banner3.gif&quot;,&quot;banner4.gif&quot;,&quot;banner5.gif&quot;,&quot;banner6.gif&quot;,&quot;banner7.gif&quot;);
if($date_time_array[&quot;weekday&quot;]==&quot;Sunday&quot;){
echo&quot;<img src='$banner_array[0]' width='468' height='60' border='0'>&quot;;
}else if($date_time_array[&quot;weekday&quot;]==&quot;Monday&quot;){
echo&quot;<img src='$banner_array[1]' width='468' height='60' border='0'>&quot;;
}else if($date_time_array[&quot;weekday&quot;]==&quot;Tueday&quot;){
echo&quot;<img src='$banner_array[2]' width='468' height='60' border='0'>&quot;;
}else if($date_time_array[&quot;weekday&quot;]==&quot;Wednesday&quot;){
echo&quot;<img src='$banner_array[3]' width='468' height='60' border='0'>&quot;;
}else if($date_time_array[&quot;weekday&quot;]==&quot;Thursday&quot;){
echo&quot;<img src='$banner_array[4]' width='468' height='60' border='0'>&quot;;
}else if($date_time_array[&quot;weekday&quot;]==&quot;Friday&quot;){
echo&quot;<img src='$banner_array[5]' width='468' height='60' border='0'>&quot;;
}else {
echo&quot;<img src='$banner_array[6]' width='468' height='60' border='0'>&quot;;
}
?>
 
//$date_time_array = getdate (time());

$weekday=date(&quot;w&quot;)+1; //create a weekday 1-7


$banner_array = array(&quot;banner1.gif&quot;,&quot;banner2.gif&quot;,&quot;banner3.gif&quot;,&quot;banner4.gif&quot;,&quot;banner5.gif&quot;,&quot;banner6.gif&quot;,&quot;banner7.gif&quot;);


echo&quot;<img src='$banner_array[$weekday]' width='468' height='60' border='0'>&quot;;




Bastien

cat, the other other white meat
 
Even shorter:
Code:
echo ('<img src=&quot;$banner'.(date(&quot;w&quot;)+1).'&quot;  width=&quot;468&quot; height=&quot;60&quot; border=&quot;0&quot;>');
Please note that valid HTML should have arguments in double quotes. ;)
 
Two mistakes, however, I overlooked:
no $ sign for the graphics name and the extension is to be added. It should be:
Code:
echo ('<img src=&quot;banner'.(date(&quot;w&quot;)+1).'.gif&quot;  width=&quot;468&quot; height=&quot;60&quot; border=&quot;0&quot;>');

Will work as long as all banners are named bannern.gif
 
Yes that's good. Another thing I noticed with Bastiens reply is that the '+1' part of this: $weekday=date(&quot;w&quot;)+1;
is unecessary as arrays start at 0. But again thanks to you both, it's much better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top