SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Help me please
-
Jan 3, 2005, 21:46 #1
- Join Date
- Oct 2003
- Location
- Malaysia
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help me please
PHP Code:<?php
//
//this is to generate a random picture from a selected directory.
//the image files must follow the pattern: 1.jpg, 2.jpg, 3.jpg.
//
//
//Things to check and change.
//
$folder = "../pic/"; //path to the folder. (html style) (leave trailing slash)
$number = 20; //number of pictures in the folder
//
//The actual program itself.
//
//getting a random number from 1 to whatever user specified.
$random_number = rand(1, 20);
//changing the number into a string for use with the image path.
$random_number = settype($random_number, "string");
//generating the image path.
$image=$folder.$random_number.".jpg";
//displaying the image.
echo "<img src=\"$image\">";
//Volia :)
?>
Could someone tell me where I went wrong? ThanksNew site: www.talkutas.com
-
Jan 3, 2005, 21:56 #2
- Join Date
- Oct 2004
- Location
- New Jersey
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Take out the
PHP Code://changing the number into a string for use with the image path.
$random_number = settype($random_number, "string");
-
Jan 3, 2005, 22:03 #3
- Join Date
- Oct 2003
- Location
- Malaysia
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Let me try...
New site: www.talkutas.com
-
Jan 3, 2005, 22:04 #4
- Join Date
- Oct 2003
- Location
- Malaysia
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, it works.
But why?New site: www.talkutas.com
-
Jan 3, 2005, 22:06 #5
- Join Date
- Oct 2004
- Location
- New Jersey
- Posts
- 235
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
To be honest with you, I'm not sure why; I just tested it out on my server and it seemed to do the trick.
-
Jan 3, 2005, 23:19 #6
- Join Date
- Nov 2004
- Location
- Parry Sound, ON
- Posts
- 725
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's because settype returns a boolean true on success, not the value of its argument. So you had assigned TRUE to $random_number, and since you'd also set $random_number's type to string it became "1".
So you should have just done this:
PHP Code://changing the number into a string for use with the image path.
settype($random_number, "string");
-
Jan 4, 2005, 02:59 #7
- Join Date
- Oct 2003
- Location
- Malaysia
- Posts
- 231
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks guys
New site: www.talkutas.com
Bookmarks