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

 

 (#494 2004-02-05 06:23:40) Post Reply
Page 0 1 2

ScriptME
Need To Set


Enrolled: Feb 2004
Posts: 5
AP: 1

Oops I forgot to also ask, what would happen if each category had a different number of elements? How would I use count then, b.c if one Array had 5 elements and another 2, then this could cause problems.

Thanks,
ScriptME

 

 (#495 2004-02-05 06:24:34) Post Reply
Page 0 1 2

ScriptME
Need To Set


Enrolled: Feb 2004
Posts: 5
AP: 1

Oops I forgot to also ask, what would happen if each category had a different number of elements? How would I use count then, b.c if one Array had 5 elements and another 2, then this could cause problems.

Thanks,
ScriptME

 

 (#540 2004-03-04 23:57:06) Post Reply
Page 0 1 2

slinky
Need To Set


Enrolled: Feb 2004
Posts: 7
AP: 1


This is so easy its only hard to spell the things :D all my TO DO things will be at www.kirk.forgedhosting.com/ss/index.php

banners.php:

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

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94

"banner6.jpg\">
"
<img src=

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94

"banner7.jpg\">
"
<img src=

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94

"banner8.jpg\">
"
<img src=

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /web/sites/tdavid/non_public_system/parsemsg.php on line 94

"banner9.jpg\">");
?>

banner array
//randomly picks a banner from the array

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

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

print(
"images/$banners[$banner]");
?>


 

 (#562 2004-03-23 08:38:12) Post Reply
Page 0 1 2

Emdec
Need To Set


Enrolled: Mar 2004
Posts: 8
AP: 1

2 files in the same directory -
(This does not actually rotate the banners but picks a random one on loading. I hope that this is what is required.)

Week4.inc


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




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

<body bgcolor="#FFFFFF" text="#000000">
<?
require("week4.inc");
// seed rand
mt_srand(time());

//pick a number
$Banner_no =(mt_rand(1,(count($MyBanners)))-1);

// construct the message
$MyMessage = $MyBanners[$Banner_no];

// print it oot
print $MyMessage;
?>
</body>
</html>


 

 (#568 2004-03-28 00:39:49) Post Reply
Page 0 1 2

slinky
Need To Set


Enrolled: Feb 2004
Posts: 7
AP: 1

/*dunno what went wrong b4 maybee i entered something wrong ohwell
bannerarray.php*/

<?php
$banners
=('1.gif','2.gif','3.gif');
?>

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

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

print(
"images/$banners[$banner]");
?>



 

 (#596 2004-05-25 12:57:41) Post Reply
Page 0 1 2

Beauchy
Need To Set


Enrolled: May 2004
Posts: 5
AP: 1

Main file


<HTML>
<BODY>
<TITLE>PHP Week 4 - Basic Assignment</TITLE>
<?php require("random_banner.php"); ?>
</HTML>
</BODY>



<?php
$banners
= array('<img src="../../img/hbanner1c.gif" width="400" height="59">',
'<img src="../../img/hbanner3c.gif" width="400" height="59">',
'<img src="../../img/hbanner5b.gif" width="400" height="59">',
'<img src="../../img/hbanner9b.gif" width="400" height="59">');
$random_index = (mt_rand(1, (count($banners))) - 1);
print(
$banners[$random_index]);
?>



 

 (#609 2004-05-30 21:39:30) Post Reply
Page 0 1 2

ice52us
Need To Set


Enrolled: Feb 2004
Posts: 9
AP: 1

i guess mine is the shortest one. i do not have a url, because im doing this on some local server, which allows me to view it without uploading it, and i do not want to take the time to.<br>main one.


<?
mt_srand
(time());
require (
"randomquote.php");
$rand = mt_rand (1, count ($banners));
$rand--;
print (
"<img src=\"$banners[$rand]\">");


?>




<?
//im lazy
$banners = array ("ed.gif", "me.jpg", "bullet.gif", "flag.jpg");



?>



 

 (#634 2004-06-09 23:07:16) Post Reply
Page 0 1 2

fishhead
Need To Set


Enrolled: Jun 2004
Posts: 6
AP: 1

here is the array file



<?
$banner
= array('1.gif','2.gif','3.gif','4.gif','5.gif','6.gif');
mt_srand(time());
$random_banner = (mt_rand(1,(count($banner)))-1);
print(
"<img src=\"$banner[$random_banner]\">");
?>




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




working file is
http://www.southfloridajams.com/php/week4.php

 

 (#636 2004-06-10 06:40:46) Post Reply
Page 0 1 2

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

I have a noobic question and feel shame about it, but how to enter clickable url below your homeassignment, when I want to post it into forum?

thanks for help

 

 (#641 2004-06-12 14:13:52) Post Reply
Page 0 1 2

madhatter
Need To Set


Enrolled: May 2004
Posts: 10
AP: 1

Ahkorahil, hey,
you should just have to enter the url, just type it out, the bulletin board automatically reads it as a url
http://www.yourdomain.com

 

 (#642 2004-06-12 14:40:56) Post Reply
Page 0 1 2

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

madhatter

Thanks for help! :D

But now I don't know where to hide my hide :P
shame on me

I try: http://www.noob.com

 

 (#643 2004-06-12 14:41:39) Post Reply
Page 0 1 2

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

correction:
to hide my eyes*

 

 (#683 2004-07-31 09:07:25) Post Reply
Page 0 1 2

MI4C
Need To Set


Enrolled: Jul 2004
Posts: 6
AP: 1

*******My index.php*******
<? require("extrapages/random_banner.php"); /*get the banner*/ ?>

*******My random_banner.php*******
<?
/*
I try something difficult and maybe working...
*/

$images_path = '../images';

$banners = array("eng.gif",
"sve.gif",
"fin.gif");
$links = array('www.helsinki.fi/university',
'www.helsinki.fi/universitetet',
'www.helsinki.fi/yliopisto');

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

print("<a href=\"http://$links[$random_index]\">
<img src=\"$images_path/$banners[$random_index]\"></a>");

/* After 2 hour thinking and working I finally got it working, but not like I
wanted... Does anyone know how to get that annoying link round away from the
picture... I still want that the link exists, without the link around it...
*/
// Well this was my 3rd own script...

?>

 

 (#689 2004-09-10 12:39:14) Post Reply
Page 0 1 2

lestat
Need To Set


Enrolled: Jan 2004
Posts: 44
AP: 1

Woohoo, This was easy compared to the #3 advanced with the multidimensional assignment.
However, I did have to look back now and then for the proper syntax.....

Index page:


<html>
<head><title></title></head>
<body>

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

</body>
</html>



<?
/* BASIC Assignment #4:
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. */

// Set path to images
$image_path = 'gifs';

// Set banner array
$banner_array = array('1.gif','2.gif','3.gif','4.gif','5.gif','6.gif','7.gif');

// Set random Seed
mt_srand(time());

// Set static min & random max values, by counting the
// imags in the array, to randomly display
$random_banner =(mt_rand(1, (count($banner_array)))-1);

// Print the random banner
print("<img src=\"$image_path/$banner_array[$random_banner]\">");

?>




...and it works too!

 

 (#708 2004-10-05 11:18:21) Post Reply
Page 0 1 2

Marcel
Need To Set


Enrolled: Oct 2004
Posts: 4
AP: 1

Ok..here we go :

require-file :

<?php
$banners
=array ('bannerimage1.jpg','bannerimage2.jpg','bannerimage3.jpg','bannerimage4.jpg');
mt_srand(time());
$random= mt_rand(1, (count($banners)));
$random--;
?>



<?php
require("lesson4require.php");
print
"<center><img src=$banners[$random]></center>";
?>



Going advanced now....


 

 (#770 2005-02-27 09:43:48) Post Reply
Page 0 1 2

LowenWolfe
Need To Set


Enrolled: Feb 2005
Posts: 7
AP: 1

Here are my Week #4 scripts:

The "required" script:


<?php

/*
ToDo Assignment Week 4
URL ---> <A HREF="http://sandbox.buynowshop.com/ToDo4r.php" TARGET=_blank>http://sandbox.buynowshop.com/ToDo4r.php</A>
Script for "required"
by LowenWolfe
*/

// array for banners
$banners=array(
'<img src="http://www.buynowshop.com/images/Gifts-WWC.gif">',
'<img src="http://www.buynowshop.com/images/j4ubanner.gif">',
'<img src="http://www.buynowshop.com/images/PJBanner4.gif">',
'<img src="http://www.buynowshop.com/images/BNSBannerD2.gif">'
);
?>




<html>
<head>
<title>Assignment Week 4 Basic</title>
</head>
<body>
<br>
<hr>
<?php
require("ToDo4r.php");

// randomize
mt_srand(time());
$banner_index=(mt_rand(1,(count($banners)-1)));

// display
print ("<center>$banners[$banner_index]</center>");

?>
<hr>
</body>
</html>



LowenWolfe

 

 (#777 2005-03-06 10:43:17) Post Reply
Page 0 1 2

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

My Basic Assignment #4:



<html>
<head>
<title>ScriptSchool.com Assignment 4</title>
<meta http-equiv="refresh" content="1">
</head>
<body bgcolor="666666">

<?php
// ScriptSchool.com Assignment 4 (basic)
/* Description of 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.*/
print("<center><p><b>ScriptSchool.com Assignment 4 - (basic)</b><br />
Description of assignment: Write a script to rotate banners<br />
kept inside an array stored using a separate file and using<br />
require to bring into the main script which does the rotation.</p></center>"
);

/* call external list of files (i.e. $banners) and their location
// (i.e. $image_path) */
require("banner_list.php");

// seed rand using time
mt_srand(time());

/* count the number of banners in $banners, assign result to
// maximum for mt_rand and pick a number, then subtracting 1 (one)
// for the result and assigning new result to $random_index */
$random_index = (mt_rand(1, (count($banners))) - 1);

/* print the selected banner by using $random_index on the
// $banners array with $image_path prepended so images can be found
// readily */
print("<center><img src=".$image_path.$banners[$random_index]."></center>");

?>




</body>
</html>


 

 (#811 2005-05-04 11:35:21) Post Reply
Page 0 1 2

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

I have the following script:
<HTML>
<BODY>
<?require("D:\PROGRAME INSTALATE-FUNCTIONALE\PHP Designer 2005\proiecte d'ale mele\random_quote");
?>
</BODY>
</HTML>
The random_quote file is:
<?
$pictures=array("D:\week4\poza_1.jpg","D:\week4\poza_2.jpg","D:\week4\poza_3.jpg","D:\week4\poza_4.jpg","D:\week4\poza_5.jpg");
mt_srand(time());
$random_index=mt_rand(1,count($pictures)-1);
print("<img src=\"$pictures[$random_index]\">");
?>
It gives me the following error:
Warning: main(D:\PROGRAME INSTALATE-FUNCTIONALE\PHP Designer 2005\proiecte d'ale mele andom_quote) [function.main]: failed to open stream: Invalid argument in C:\Documents and Settings\VLADUT ON LICEENI\My Documents\_debug_tmp.php on line 3

Fatal error: main() [function.require]: Failed opening required 'D:\PROGRAME INSTALATE-FUNCTIONALE\PHP Designer 2005\proiecte d'ale mele andom_quote' (include_path='.;C:\php5\pear') in C:\Documents and Settings\VLADUT ON LICEENI\My Documents\_debug_tmp.php on line 3






Can someone help me?????

 

 (#812 2005-05-05 11:51:37) Post Reply
Page 0 1 2

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

I have solved my problem.
here is a file called random_quote.php:
HTML>
<BODY>
<? //week 4 basic:
$pictures=array("D:\week4\poza_1.jpg","D:\week4\poza_2.jpg","D:\week4\poza_3.jpg","D:\week4\poza_4.jpg","D:\week4\poza_5.jpg");
mt_srand(time());
$random_index=mt_rand(1,count($pictures)-1);
print("<img src=\"$pictures[$random_index]\">");
?>
</BODY>
</HTML>

This is the file that uses random_quote:
<?include("random_quote.php")
?>
My mistake was that I put the adress of the file in the require function,and did not put the file in the root directory.
After i had put the name of the file in the require function and the file In the root directory,the program worked.
PS:I used some photos instead of banners

 

 (#823 2005-05-22 12:17:21) Post Reply
Page 0 1 2

DarePoo
Need To Set


Enrolled: May 2005
Posts: 10
AP: 1

Working URL: http://www.adr-clan.com/phplea...assignment4.php

banner file (banners.php):



<?
$banners
=array("<img src=\"img0.gif\">","<img src=\"img1.gif\">",
"<img src=\"img2.gif\">","<img src=\"img3.gif\">");
?>



<?
//Getting random in place and organising the random part
mt_srand(time());
require(
"banners.php");
$banner=mt_rand(0, (count($banners))-1);
//Print random banners
print("Random Pictures:<br> $banners[$banner]");
?>


 

 (#850 2005-08-09 08:56:52) Post Reply
Page 0 1 2

MaLeK
Need To Set


Enrolled: Jul 2005
Posts: 9
AP: 1

<?php //ASSIGNMENT 4 BASIC
mt_srand(time());
$random_index=(mt_rand(1,(count($banners)-1)));
$banners=array('banner0.jpg','banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg');
print("<img src="$banners[$random_index]">");
//we will call this file assign4basic.php3 so we can require it.
//wherever you need this random banner rotation you type:
//<? require("path/to/$assign4basic.php3*");
?>

 

 (#851 2005-08-09 09:02:51) Post Reply
Page 0 1 2

MaLeK
Need To Set


Enrolled: Jul 2005
Posts: 9
AP: 1

on my last post i forgot to say what the problem was. the images did not rotate. it stayed on the first one. however, when i type in 0,4 then it rotates fine, so i think its something wrong with the count function...but it looks good to me..soo, i don't know.

oh and even weirder, when i type both the (0,4) script and this script at the same time, it gives me side by side images, and they rotate exactly the same. im wondering how this is dependent on the other script with (0,4). any ideas?


<?php //ASSIGNMENT 4 BASIC
mt_srand(time());
$random_index=(mt_rand(1,(count($banners)))-1);
$banners=array('banner0.jpg','banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg');
print("<img src=\"$banners[$random_index]\">");
?>

 

 (#853 2005-08-09 10:30:54) Post Reply
Page 0 1 2

MaLeK
Need To Set


Enrolled: Jul 2005
Posts: 9
AP: 1

ok i now know that the problem was that the array was not defined before the count function. thanks lestat!

 

 (#885 2005-11-03 22:31:28) Post Reply
Page 0 1 2

Goudarzi
Need To Set


Enrolled: Oct 2005
Posts: 9
AP: 1

Main Script



<html>
<title>WebGoudarzi PHP script</title>
</head>
<body>

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

</body>
</html>




<?php

// Make Array with all the picture names

$picture = array("banner1.gif","banner2.gif","webgoudarzi.gif");

// Randomize a Number to choose the banner

mt_srand(time());
$random_array = mt_rand(0,(count($picture))-1);

// Print out Results

print("<img src=\"$picture[$random_array]\">");

?>



 

 (#886 2005-11-03 22:34:04) Post Reply
Page 0 1 2

Goudarzi
Need To Set


Enrolled: Oct 2005
Posts: 9
AP: 1

Main Script



<html>
<title>WebGoudarzi PHP script</title>
</head>
<body>

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

</body>
</html>




<?php

// Make Array with all the picture names

$picture = array("banner1.gif","banner2.gif","webgoudarzi.gif");

// Randomize a Number to choose the banner

mt_srand(time());
$random_array = mt_rand(0,(count($picture))-1);

// Print out Results

print("<img src=\"$picture[$random_array]\">");

?>



 

 (#887 2005-11-04 11:08:57) Post Reply
Page 0 1 2

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

To see what you are talking about, try adding a loop to check the randomizations webgourdarzi like this and notice what numbers you see:



$count = count($picture);
for($i=0;$i<100;$i++){
$random_array = mt_rand(0,$count);
print "$random_array, ";
}



$count = count($picture)-1;
for($i=0;$i<100;$i++){
$random_array = mt_rand(0,$count);
print "$random_array, ";
}



Compare the results.

 

 (#913 2005-12-30 02:23:33) Post Reply
Page 0 1 2

Dylan
Need To Set


Enrolled: Dec 2005
Posts: 14
AP: 1

http://www.babyian.com/psi/homework.php

First rndbanner.php contains my array:


<?php

// This script will be called from the main page

// Create an array storing some banners
$banners = array("vote_2008.gif",
"GoreBlog.jpg",
"Donate_in_08.gif",
"SubscribeNow.jpg");
?>




<html>
<body>

<?php

// Week 4 Assignment
// Write a script to rotate banners kept inside an array
// using a seperate file and using require to bring into
// the main script which does the rotation.

require("rndbanner.php");

// choose a banner randomly
mt_srand(time());
$random_index = (mt_rand(1, (count($banners))) - 1);

// Show the chosen banner
print("<img src = \"".$banners[$random_index]."\">");

?>

</body>
</html>


 

 (#940 2006-02-17 01:26:45) Post Reply
Page 0 1 2

prezbedard
Need To Set


Enrolled: Jan 2006
Posts: 4
AP: 1

ok one minor typo but fixed it
I used the state flags of New England as my subject.

the reqiure file

<?
// Array storing the 6 flags of the New England States

$nestates = array('CT.GIF','MA.GIF','ME.GIF','NH.GIF','RI.GIF','VT.GIF');

?>



<?
// Require file storing array code
require("week4hw1.php"); ?>
<?
/* Randomly display the 6 New England state flags */

mt_srand(time());
$random_index = (mt_rand(1, (count($nestates))) - 1);
print(
"<img src=\"$nestates[$random_index]\">");
//print("<img src=\"$images[$day_of_week]\">");
?>



 

 (#948 2006-02-21 18:47:42) Post Reply
Page 0 1 2

anti
Need To Set


Enrolled: Feb 2006
Posts: 11
AP: 1

here is file #1 start page that calls the script


<html>
<head>
<title>Week #4 Basic TO-DO ASSIGNMENT : Start page to call other file</title>
</head>
<body>
<center> <? require("ass4.php"); ?> </center> <!-- this line of code is to call the page hold the script -->
</body>
</html>



<?
/*
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.
*/

//set banner array
$banner = array('banner-1.jpg',
'banner-2.jpg',
'banner-3.jpg',
'banner-4.jpg',
'banner-5.jpg'
);
mt_srand(time());
// randomize the banner output
$banner_rotate = (mt_rand(1, (count($banner))) - 1);
//output string
$output = ($banner[$banner_rotate]);
//print to browser
Print("<img src=\"images/$output\"> ");
?>



 

 (#983 2006-03-28 04:48:54) Post Reply
Page 0 1 2

DrgnLdy
Need To Set


Enrolled: Jan 2006
Posts: 3
AP: 1

I'm missing something here but can not for the life of me figure out what it is...probably something real simple that I am overlooking...any help would be greatly appreciated



<?php
//set banner array
$banner = array('062.jpg','065.jpg','068.jpg','070.jpg','063.jpg');
mt_srand(time());
$rotate_banner = (mt_rand(1,(count($banner)))-1);
//print to browser
Print("<img src=\"$banner[$random_banner]\"></center>");
?>

<html>
<head>
<title>Our Picture of the Day</title>
</head>
<BODY bgcolor="#800080" TEXT="#FFFFFF"><br>
<div align="center">
<h1>Our Picture Of The Day - Enjoy</h1><br>
</BODY>
</HTML>




 

  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