School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #4 Basic To-Do Assignment, post here
 

 (#6 2003-08-07 16:03:54) Post Reply
Page 0 1 2

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Week #4 Basic TO-DO ASSIGNMENT: Write a script to rotate banners kept inside an array stored using a separate file and using require() to bring into the main script which does the rotation.

Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and post here the complete source code of the script in you post.

scriptname.php <-- script name

Good luck to you!

 

 (#53 2003-08-17 14:15:37) Post Reply
Page 0 1 2

cplayers
Need To Set


Enrolled: Aug 2003
Posts: 1
AP: 1

Hi,

This is my two scripts and working URL - comments

URL: http://www.online-players.com/...asic_rotate.php

Banner Script:
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Script School - PHP Course Lesson 4 (basic File 1 of 2)</title>
</head>
<BODY>
<?
/* Array of Banners */
$banners = array("http://www.online-players.com/Graphics/468x60_june02.gif",
"http://www.online-players.com/Graphics/468X60FREEBOX_GOLDBAR_25_50_75.gif",
"http://www.online-players.com/Graphics/gcc_468x060_115.gif",
"http://www.online-players.com/Graphics/op_gambling_portal_468x60_u12.gif");
?>
</HTML>
</BODY>

Main Script:
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Script School - PHP Course Lesson 4 (basic File 2 of 2)</title>
</head>
<BODY>
<? require("/home/online-p/public_html/phplessons/lesson4_basic_array.php"); ?>
<?
mt_srand(time());
$random_index = (mt_rand(1, (count($banners))) - 1);
print("<img border="0" src=" . $banners[$random_index] . ">");
?>
</HTML>
</BODY>

 

 (#59 2003-08-17 19:20:00) Post Reply
Page 0 1 2

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

Heres my banner rotation script:

Inside 'Week #4 Basic To-Do Assignment.php'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #4 Basic To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<center>
Here is our random banner:<br />
<?php require("random_baner.php"); ?>
</center>
</body>
</html>

Inside 'random_baner.php':


<?php
// Basic Random Banner Generator By Sk8rRIMuk - 18/08/2003
$quotes=array(
'<a href="http://www.n00bstories.com" target="_blank"><img src="n00bstories.jpg" border="0" alt="n00bstories" /></a>',
'<a href="http://www.google.co.uk" target="_blank"><img src="google.gif" border="0" alt="Google UK" /></a>',
'<a href="http://www.eagames.com" target="_blank"><img src="eagames.jpg" border="0" alt="EA Games" /></a>',
'<a href="http://www.katikai.com" target="_blank"><img src="katikai.png" border="0" alt="Katikai Webhosting" /></a>'
);
mt_srand(time());
$random_index=(mt_rand(1,(count($quotes)))-1);
print(
$quotes[$random_index]);
?>



In the directory I have all the required pictures.

I am still stuck on Week #3 Advanced.

I will have ago at Week #4 Advanced some time this week.

 

 (#62 2003-08-19 07:15:15) Post Reply
Page 0 1 2

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

My script is at:
http://www.katikai.com/ee/assi...0Assignment.php

Sorry for the big link I just uploaded my scripting folder there.

All my previous to-do assignments are at:
http://www.katikai.com/ee/assi...Do%20Assignment

 

 (#89 2003-08-25 12:34:36) Post Reply
Page 0 1 2

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

I have a script called bannerarray.php. It contains the following code:



<?php
//Script to store banners in an array
$banners=array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
mt_srand(time());
$random_index=(mt_rand(1,(count($banners)))-1);
print(
"<img src = "$banners[$random_index]">");
?>




<HTML>
<HEAD>
<TITLE>Random Banner Page</TITLE>
</HEAD>
<BODY>
<?php
require("bannerarray.php");
?>

</BODY>
</HTML>



if I execute the .php file, it works perfectly. If I open the html file, nothing is displayed. Just a blank page. Can anyone help me? Thanks.

 

 (#121 2003-08-29 15:35:20) Post Reply
Page 0 1 2

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

I have two files:

First a php script called bannerarray.php:



<?php
//Script to store banners in an array
$banners=array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
mt_srand(time());
$random_index=(mt_rand(1,(count($banners)))-1);
print(
"<img src = "".$banners[$random_index]."">");
?>




<HTML>
<HEAD>
<TITLE>Random Banner Page</TITLE>
</HEAD>
<BODY>
<?php
require("localhost/bannerarray.php");
print(
"<img src = "".$banners[$random_index]."">");
?>

</BODY>
</HTML>



If I just execute the php filefrom the browser, everything works great. If I open the html file, it doesn't work. Any suggestions?

 

 (#132 2003-08-29 21:40:00) Post Reply
Page 0 1 2

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Hi Donnie,

quote:
If I just execute the php filefrom the browser, everything works great. If I open the html file, it doesn't work. Any suggestions?


Make sure the (html) page calling the script is set to parse for PHP. You might need to give it a php, phtml, php3 extension or have your host parse the html page for php.

 

 (#133 2003-08-29 21:41:35) Post Reply
Page 0 1 2

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

cplayer - please make sure to use the [ code ] and [ /code ] tags around your php code so that the forum colorizes it.

Banner Script:



<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Script School - PHP Course Lesson 4 (basic File 1 of 2)</title>
</head>
<BODY>
<?
/* Array of Banners */
$banners = array("http://www.online-players.com/Graphics/468x60_june02.gif",
"http://www.online-players.com/Graphics/468X60FREEBOX_GOLDBAR_25_50_75.gif",
"http://www.online-players.com/Graphics/gcc_468x060_115.gif",
"http://www.online-players.com/Graphics/op_gambling_portal_468x60_u12.gif");
?>
</HTML>
</BODY>

Main Script:
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Script School - PHP Course Lesson 4 (basic File 2 of 2)</title>
</head>
<BODY>
<? require("/home/online-p/public_html/phplessons/lesson4_basic_array.php"); ?>
<?
mt_srand
(time());
$random_index = (mt_rand(1, (count($banners))) - 1);
print(
"<img border="0" src=" . $banners[$random_index] . ">");
?>
</HTML>
</BODY>



Like that, thanks ;)

 

 (#150 2003-09-02 10:47:18) Post Reply
Page 0 1 2

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

OK, I have finished the basic assignment 4. I have two files; The first one assigns image files to to an array then randomly selects one. The second calls the first script then displays the randomly selected image.

First File


<?php
//Script to store banners in an array
//First, put the banners in an array
$banners = array('BANNERCAT1BAN1.jpg','BANNERCAT1BAN2.jpg','BANNERCAT1BAN3.jpg');
//Select a random banner
mt_srand(time());
$random_index = (mt_rand(1,(count($banners)))-1);
?>




<HTML>
<HEAD>
<TITLE>Random Banner Page</TITLE>
</HEAD>
<BODY>
<?php
//require the php file to select the random banner
require("phpbasicassignment4bannerarray.php");
//print the banner to the screen
print("<img src = \"".$banners[$random_index]."\">");
?>

</BODY>
</HTML>




BTW - Thanks for fixing the backslash issue!!!!


 

 (#158 2003-09-03 19:34:39) Post Reply
Page 0 1 2

galacey
Need To Set


Enrolled: Aug 2003
Posts: 7
AP: 1

Working file: http://www.helping-you-make-mo...ndom_banner.php

banners.php - external file that contains the array of banners



<?php

/*This file contains the banners to be used which are stored in the
following array*/

$banners=array('../468_60_lkwrs_b_anim.gif','../logo.gif',
'../html/logo2.gif','../samples/autorespondermagic/amagic_top.gif',
'../samples/mde/Million_Dollar_Header2.jpg','../wsanswers/banner27.jpg',
'../xfactor/banner.jpg');

?>




<?php

//This file displays a random banner from the array in banners.php

//Indicates where the external file containing the banners is
require("banners.php");

//Seed the random generator
mt_srand(time());

/*Calculates a random number between 1 and the number of banners in the
array $banners and one is subtracted because arrays start at zero.
(count($banners)) is used so that banners may be added or removed from
the external file without this script having to be changed*/
$random_banner=(mt_rand(1,(count($banners)))-1);

/*Display the resulting banner using the variable $random_banner as the
index for the $banners array*/
print("<img src=\"$banners[$random_banner]\">");

?>



 

 (#171 2003-09-09 10:43:54) Post Reply
Page 0 1 2

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

this was easy :)

banners.php:



<?
$banners
= array("<img src=\"banner1.jpg\">","<img src=\"banner2.jpg\">","<img src=\"banner3.jpg\">","<img src=\"banner4.jpg\">");
?>




<?
mt_srand
(time());
require(
"banners.php");

$whichone = mt_rand(0, (count($banners))-1);

print(
"$banners[$whichone]");
?>




working url

 

 (#172 2003-09-09 10:45:20) Post Reply
Page 0 1 2

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

sorry, the second bit of code belongs to the file that the link goes to, not the banners.php (im pretty sure i wrote its name before the code but whatever)

 

 (#198 2003-09-13 16:46:12) Post Reply
Page 0 1 2

operations
Need To Set


Enrolled: Sep 2003
Posts: 8
AP: 1

http://members.lycos.co.uk/operations/

week4_basic_netsurprise.php :



<?php

/**
* ASSIGNMENT 4 basic: Write a script to rotate banners kept inside an array stored using
* a separate file and using require to bring into the main script which does the rotation.
*/
include "week4_basic_require.php";

?>
<Title>Script School Assignment 4 Basic</Title>
<center>
<?php
// What you see
Print ("<IMG SRC=\"$banners[$random_banner]\">");

?>




<?php

/**
* This is the require file
*/

$banners = array("banners/themexp.gif",
"banners/atw.gif",
"banners/belchfire.jpg",
"banners/devshed.gif",
"banners/google.gif",
"banners/samurise.jpg");

mt_srand(time());
$random_banner = mt_rand(1, (count($banners)-1));

?>



 

 (#208 2003-09-15 09:58:49) Post Reply
Page 0 1 2

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

Here is my assignment

Class04_banner.php


<?
$bannerarray
= array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg');
$bannerlink=array('www.1.com','www.2.com','www.3.com','www.4.com');
mt_srand(time());
$random_index = mt_rand(1, (count($bannerarray)));
$random_index--;
?>

<a href="http://<? print($bannerlink[$random_index]) ?>"><img src="./<? print($bannerarray[$random_index]) ?>"></a>



<Title>Assignment 04 Advanced Script School - URL of the Month</title>

<?
require("class04_banner.php")
?>
<br>
^---Click to Link---^






 

 (#219 2003-09-16 19:51:59) Post Reply
Page 0 1 2

Nazz
Need To Set


Enrolled: Aug 2003
Posts: 8
AP: 1


<?
/*This file "4th_assigmrnt_html.php" contains banner array to seed, calculate, and print banner*/


/*create banner array*/
$banner = array("9227.gif",
"9246.gif",
"9239.gif",
"9251.gif");


/*seed random generator*/
mt_srand(time());
/*calculate random number*/
$random_banner = (mt_rand(1, (count($banner))) - 1);
/*print to browser*/
print("<img src=\"$banner[$random_banner]\">");
?>

<?
/* this file "4th_assignment_2_html.php" uses the require function*/
require("4th_assignmrnt_html.php");
?>


 

 (#220 2003-09-16 19:57:59) Post Reply
Page 0 1 2

Nazz
Need To Set


Enrolled: Aug 2003
Posts: 8
AP: 1

sorry to post again but I forgot the closing code tag the first time.


<?
/*This file "4th_assigmrnt_html.php" contains banner array to seed, calculate, and print banner*/


/*create banner array*/
$banner = array("9227.gif",
"9246.gif",
"9239.gif",
"9251.gif");


/*seed random generator*/
mt_srand(time());
/*calculate random number*/
$random_banner = (mt_rand(1, (count($banner))) - 1);
/*print to browser*/
print("<img src=\"$banner[$random_banner]\">");
?>

<?
/* this file "4th_assignment_2_html.php" uses the require function*/
require("4th_assignmrnt_html.php");
?>


 

 (#258 2003-09-20 10:24:08) Post Reply
Page 0 1 2

merlin69
Need To Set


Enrolled: Sep 2003
Posts: 4
AP: 1

Here is my banner.php


<?php
$quotes
= array("<a href=\"http://www.scriptschool.com\"><img scr=\"/images/img0.gif\"></a>",
"<a href=\"http://www.realm-of-merlin.com/school/week3.php\"><img scr=\"/images/img1.gif\"></a>",
"<a href=\"http://www.realm-of-merlin.com/school/week3.php\"><img scr=\"/images/img2.gif\"></a>",
"<a href=\"http://www.scriptschool.com\"><img scr=\"/images/img3.gif\"></a>",);

mt_srand(time());
$random_index = (mt_rand(1, (count($quotes))) - 1);
print(
$quotes[$random_index]);
?>




<html>
<head>
<title>Week 4 Practical Demo</title>
</head>
<body>

<? require("banner.php"); ?>



the script works just fine however I am having a heck of a time getting the images to show.

 

 (#279 2003-09-26 09:08:36) Post Reply
Page 0 1 2

MarcusD79
Need To Set


Enrolled: Sep 2003
Posts: 10
AP: 1

This works quite well. Here is the link to the referrenced file: http://www.fagfrat.com/phpclas...week4banner.php
and here is the file that displays: http://www.fagfrat.com/phpclass/week4.php

Here is the reference file code, followed by the display file code:


<?php

//array of banners
$_banner=array('http://www.cocodorm.com/links/images/animated/mxb.gif',
'http://www.mixitupboy.com/links/images/animated/ccb.gif',
'http://www.mixitupboy.com/links/images/animated/ccd.gif',
'http://www.mixitupboy.com/links/images/animated/thg.gif',
'http://www.mixitupboy.com/links/images/animated/ola.gif',
'http://www.mixitupboy.com/links/images/animated/bhk.gif',
'http://www.mixitupboy.com/links/images/animated/taggaz.gif',
'http://www.mixitupboy.com/links/images/animated/gayeroticexpo.jpg',
'http://www.mixitupboy.com/media/links/cocoboyz-banner.gif',
'http://www.mixitupboy.com/media/links/olatin-banner.gif',
'http://www.mixitupboy.com/media/links/thugboy-banner.gif');

$_random_banner=mt_rand(1,(count($_banner)));
$_random_banner--;
?>
////////////////*
Referrence file ends, Display file begins
*////////////////


<html>
<head>
<title>Week #4 Basic - Banner Rotation</title>
</head>

<body>
<center>Week #4 Basic - Banner Rotation</center>
<br>
<?php

mt_srand
(time());
require(
"week4banner.php");
print(
"<img src=\"$_banner[$_random_banner]\">");

?>

</body>
</html>


 

 (#281 2003-09-26 15:55:14) Post Reply
Page 0 1 2

maddy
Need To Set


Enrolled: Sep 2003
Posts: 14
AP: 1

The fine containing the banners array (called banners.php), contains this code:

<?
//create an array of banners to rotate. i have 11.
$banners = array("i_think.gif",
"i_hope.gif",
"like_learn.gif",
"font_pollock.gif",
"bumble_bee.gif",
"bright_green.gif",
"fast_red.gif",
"kinda_fun.gif",
"how_challenge.gif",
"great_grey.gif",
"like_learn.gif",
"dark_colour.gif");
?>



<?
//lets call in that banners array, eh. we always need it, so i think require is called for?
{
require(
"/home/virtual/site420/fst/var/www/html/scripts/banners.php");
}

//and now lets randomise their display.
mt_srand(time());
$random_index = (mt_rand(1, (count($banners))) - 1);
$displaybanner = $banners[$random_index];

//And lets print it out.
print("<img src=\"http://sassy.togetherhost.com/scripts/images/$displaybanner\" alt=\"banner\" />");
?>




A working copy (I think) of the script can be found <a href="http://sassy.togetherhost.com/scripts/week4.php">here</a>.

 

 (#282 2003-09-26 15:59:48) Post Reply
Page 0 1 2

maddy
Need To Set


Enrolled: Sep 2003
Posts: 14
AP: 1

Well, obviously the second set of code is what contains the randomising code, and prints out the random image. I did put that in my first post, between the two sets of code, but I guess it got eaten. And now that I know that the forum doesn't have html enabled, here is the link for my script: http://sassy.togetherhost.com/...ripts/week4.php :)

 

 (#317 2003-10-13 14:11:30) Post Reply
Page 0 1 2

zxrod
Need To Set


Enrolled: Oct 2003
Posts: 7
AP: 1

Ok, for some reason its been taking me a little bit of time to get this whole "<img src=\"lala.jpg\">" but oh well. This seems to work.

Banners.php3
<html>
<body>
<title>Week 4 Basic Assignment</title>


<?php
/* No need to seed the Generator in this code because it is seeded in the body
of the other code */
$banners=array('dong.jpg','mungusin.jpg','scoobiedoobie.jpg','tweedart.jpg');
$bannerand = (mt_rand(1,(count($banners)))-1);
?>




<?php
//Seed the Generator
mt_srand(time());
require(
"Banners.php3");
print(
"<img src=\"$banners[$bannerand]\">");
?>



</body>
</html>

 

 (#333 2003-10-25 00:27:27) Post Reply
Page 0 1 2

willie565
Need To Set


Enrolled: Oct 2003
Posts: 5
AP: 1

Here's assignment 4 I've done 4 in one night so I think I'll take a break now. http://www.megatech.com/~will/banner.php
banner.php:


<html>
<?php
mt_srand
(time());
$randomize=mt_rand(1,100);
if(
$randomize <= 50){
include(
"bannerm.php");
mt_srand(time());
$randomize=mt_rand(0,2);
function
make_seed() {
list(
$usec, $sec) = explode(' ', microtime());
return (float)
$sec + ((float) $usec * 100000);
}
mt_srand(make_seed());
$randomize1=mt_rand(0,2);
echo(
"Random Link ".$allc[$randomize][$randomize1]."<br>");
}
else{
echo(
"There Is a 50% chance To display on But this time it didn't happen");
}
?>
</html>



<?
$urlc
=array('Random url category 1','Random url category 1-2','Random url category 1-3');
$urlc2=array('Random url category 2','Random url category 2-2','Random url category 2-3');
$urlc3=array('Random url category 3','Random url category 3-2','Random url category 3-3');
$allc=array($urlc,$urlc2,$urlc3);
?>



 

 (#393 2003-11-19 17:21:18) Post Reply
Page 0 1 2

coinweb
Need To Set


Enrolled: Nov 2003
Posts: 4
AP: 1

Here it is, took some working.
This first script is the page that stores the array of banners.
++++++++++++++++++++++++++++++++++++++++++++++

<html>
<head>
<title>Homework for Week #4</title>
</head>
<body>

<?
/* TO-DO ASSIGNMENT: Write a script to rotate banners kept inside an array stored using
a separate file and using require to bring into the main script which does the rotation.
*/

//This page is where the banners are stored
//Array of banners to be displayed
$banners = array("americanbanner.gif",
"banner1.jpg",
"oscommerce.gif",
"rent_banner.gif");
?>

</body></html>

+++++++++++++++++++++++++++++++++++++++++++++
This second script is the page that displays the banners.

<html>
<head>
<title>Homework for Week #4</title>
</head>
<body bgcolor="blue">

<center><table width="75%" border="1" bgcolor="white">
<tr>
<td>

<?php
/* TO-DO ASSIGNMENT: Write a script to rotate banners kept inside an array stored using
a separate file and using require to bring into the main script which does the rotation.
*/

//This is the page that will actually display the banners.

require("weekfour.php");

mt_srand(time());
$random_index = (mt_rand(1, (count($banners))) - 1);
print("<center><img src=" . $banners[$random_index] . "></center>");
?>

</body>
</HTML>


 

 (#416 2003-12-11 08:15:36) Post Reply
Page 0 1 2

fudded
Need To Set


Enrolled: Dec 2003
Posts: 5
AP: 1

I have 2 files in the same directory
1st the banners



<html>
<head>
<title>banner</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body><?php
$banner
= array('<table width="75%" border="4" align="center" bordercolor="#FF0000">
<tr>
<td><div align="center">
<h1><font color="#00FF00">Banner 1</font></h1>
</div></td></tr></table>'
,
'<table width="75%" border="4" align="center" bordercolor="#0000FF">
<tr>
<td><div align="center">
<h1><font color="#CC6699">Banner 2</font></h1>
</div></td>
</tr>
</table>'
,
'<table width="75%" border="4" align="center" bordercolor="#FF0000">
<tr>
<td><div align="center">
<h1><font color="#00FF00">Banner 3</font></h1>
</div></td></tr></table>'
,
'<table width="75%" border="4" align="center" bordercolor="#FF0000">
<tr>
<td><div align="center">
<h1><font color="#00FF00">Banner 4</font></h1>
</div></td></tr></table>'
);



?>
</body>
</html>
[\code]

next the main page



<html>
<head>
<title>Lesson 4</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
require ("banner.php");
//seed the random generator
mt_srand(time());
//count elements in array
$random_banner = mt_rand(1, (count($banner))-1);
//output to browser
print("$banner[$random_banner]");
?>
</body>
</html>
[\code]


 

 (#434 2003-12-28 00:04:28) Post Reply
Page 0 1 2

n2o2k
Need To Set


Enrolled: Dec 2003
Posts: 6
AP: 1

2 Files: main file and rotate file

here is the main file:


<?
/****************************************
* To do Assignement #4 *
* by n2o_2k *
*****************************************/
?>
<html>
<HEAD>
<TITLE>SchoolScript.com Assignment #4 - URL of the Day</TITLE>
</HEAD>
<BODY>
<?

//main script
require("rotate_banner.php");
print(
"<br><br>".date("m/d/y")."<br>");

?>
</html>



<?php

//script for rotating banners inside an array

//creating the banner array
$banner_array = array("0"=>array("banner1.jpg", "www.banner1.com", "description for banner 1"),
"1"=>array("banner2.jpg", "www.banner2.com", "description for banner 2"),
"2"=>array("banner3.jpg", "www.banner3.com", "description for banner 3"),
"3"=>array("banner4.jpg", "www.banner4.com", "description for banner 4"),
"4"=>array("banner5.jpg", "www.banner5.com", "description for banner 5"));

//seed the random function
mt_srand(time());

//generate the random banner
$rnd_banner= mt_rand(0, count($banner_array)-1);

//display the banner
print('<a href="http://'.$banner_array[$rnd_banner][1].
'" target=_blank><img src="'.$banner_array[$rnd_banner][0].
'" alt="'.$banner_array[$rnd_banner][2].'"></a>');
?>



 

 (#440 2003-12-29 19:44:59) Post Reply
Page 0 1 2

PureGrain
Need To Set


Enrolled: Nov 2003
Posts: 14
AP: 1

File name:lesson4basic_final.php
<a href="http://12.202.159.36/scriptschool/lesson4basic_final.php">Working link</a>

File 1: File containing the array.


<html>
<head>
<title>Lesson 4 Basic Array</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
//setting the arrays
//I managed to get this to work two ways..
/*Example : $banner=array('<img src="images/sunday.gif">'
worked without me having to put in double quotes or backslash's
but for this assignment I figured i would do it the way it
shows to do it in other exercises as well. =)
*/
$banner=array("<img src=\"images/sunday.gif\">",
"<img src=\"images/monday.gif\">",
"<img src=\"images/tuesday.gif\">",
"<img src=\"images/wednesday.gif\">",
"<img src=\"images/thursday.gif\">",
"<img src=\"images/friday.gif\">",
"<img src=\"images/saturday.gif\">"
);
//setting the seed
mt_srand(time());
//getting the size of the array
$random=(mt_rand(1,(count($banner)))-1);
//print to the browser
print("<p><center>$banner[$random]</center></p>");
?>
</body>
</html>



<html>
<head>
<title>Lesson 4 Basic Final</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><p align="center">(basic) TO-DO ASSIGNMENT: Write a script to rotate banners kept
<br>inside an array stored using a separate file and using require
<br>to bring into the main script which does the rotation.<br>
Code begins below this line:<hr>
</p>

<?
//The require function
require("lesson4basic_array.php");
?>

</body>
</html>



 

 (#477 2004-01-17 11:00:06) Post Reply
Page 0 1 2

Ash2k4
Need To Set


Enrolled: Jan 2004
Posts: 7
AP: 1

week4basic.php


<HTML>
<HEAD>
<TITLE>ScriptSchool.com - 16 week PHP Course - TO-DO ASSIGNMENT #4 BASIC</TITLE>
</HEAD>
<BODY>
<?
include('banner.php')
?>
<a href="http://<? print($bannerurl[$randombanner]) ?>"><img src="./<? print($banner[$randombanner]) ?>" border="0"></a>
</BODY>
</HTML>



<?php
//sets the urls and banner filenames into arrays
$bannerurl = array(
'www.fontfinder.ws',
'www.rentacoder.com',
'www.prohosting.com',
'www.rawkcomputing.com',
'www.ftigraphix.com',
'www.forumforwebmasters.com');
$banner = array(
'banner1.gif',
'banner2.jpg',
'banner3.gif',
'banner4.gif',
'banner5.gif',
'banner6.gif');
//defines the function mt_rand so that it runs from the current server time
mt_srand(time());
//randomises a banner number
$randombanner = mt_rand(1,count($banner));
//subtracts one from the random total as arrays start at 0
$randombanner--;
?>



 

 (#478 2004-01-17 11:04:07) Post Reply
Page 0 1 2

Ash2k4
Need To Set


Enrolled: Jan 2004
Posts: 7
AP: 1



<HTML>
<HEAD>
<TITLE>ScriptSchool.com - 16 week PHP Course - TO-DO ASSIGNMENT #4 BASIC</TITLE>
</HEAD>
<BODY>
<?
include('banner.php')
?>
<a href="http://<? print($bannerurl[$randombanner]) ?>"><img src="./<? print($banner[$randombanner]) ?>" border="0"></a>
</BODY>
</HTML>



<?php
//sets the urls and banner filenames into arrays
$bannerurl = array(
'www.fontfinder.ws',
'www.rentacoder.com',
'www.prohosting.com',
'www.rawkcomputing.com',
'www.ftigraphix.com',
'www.forumforwebmasters.com');
$banner = array(
'banner1.gif',
'banner2.jpg',
'banner3.gif',
'banner4.gif',
'banner5.gif',
'banner6.gif');
//defines the function mt_rand so that it runs from the current server time
mt_srand(time());
//randomises a banner number
$randombanner = mt_rand(1,count($banner));
//subtracts one from the random total as arrays start at 0
$randombanner--;
?>


(sorry for reposting... I posted incorrectly above)

 

 (#480 2004-01-19 15:21:37) Post Reply
Page 0 1 2

vladdrac
Need To Set


Enrolled: Dec 2003
Posts: 14
AP: 1

here is the working url http://vladdracworld.hostrocke...ests/pathto.php

here is the working code



<?php



//path to banner pic
$p = "http://vladdracworld.hostrocket.com/phptests/";

//banner array
$banner = array("banner1.jpg", "banner2.jpg", "banner3.jpg", "banner4.jpg");

//random function for banner
$random_index = (mt_rand(1, (count($banner)))-1);

//shows the banner
print("<img src = \"$p$banner[$random_index]\"></img>");


?>







<? require("http://vladdracworld.hostrocket.com/phptests/rotateb.php"); ?>





 

 (#493 2004-02-05 06:21:35) Post Reply
Page 0 1 2

ScriptME
Need To Set


Enrolled: Feb 2004
Posts: 5
AP: 1

I got my Script to work but, I know its not perfect. Is there a way to do a count on a multi-dimensional array? How would I use a count in the following code to count the number of elements in the Banner Array?




<html>
<head>
<title>Banner Rotator</title>
</head>

<body>

<?
$cat1
=Array('c1-1','c1-2','c1-3');
$cat2=Array('c2-1','c2-2','c2-3');
$cat3=Array('c3-1','c3-2','c3-3');
$Banner=Array($cat1,$cat2,$cat3);

mt_srand(time());

$percentage = mt_rand(1, 100);
if (
$percentage <=70)
{
$index = (mt_rand(1, (count($cat2))) -1 );

printf("Today's category is ". $Banner[1][$index]);
}
else
{
$cat = (mt_rand(1, (count($Banner))) -1 );
$index = (mt_rand(1, (count($cat1))) -1 );

printf("Today's category is ". $Banner[$cat][$index]);
}

?>


</body>
</html>




Thanks in advance,
ScriptME

 

  Page 0 1 2

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission