A Conversation for Use PHP to get a random background colour for a website
- 1
- 2
Peer Review: A891506 - Use PHP to get a random background colour for a website
R'win Started conversation Dec 4, 2002
Entry: Use PHP to get a random background colour for a website - A891506
Author: R'win - U209791
A tutorial for creating a fairly simple PHP script for a random background colour on a website.
Both of the final scripts should work, as long as the server understands PHP
A891506 - Use PHP to get a random background colour for a website
There is only one thing worse than being Gosho, and that is not being Gosho Posted Dec 4, 2002
The content of this entry is not something I have a great deal of knowledge of, but the writing and layout look excellent
A891506 - Use PHP to get a random background colour for a website
R'win Posted Dec 4, 2002
Thanks
I tried the two final scripts and they both work. (I actually made the first script earlier this year for one of my websites, and the second was an idea I had when I decided to write the entry.)
A891506 - Use PHP to get a random background colour for a website
HappyDude Posted Dec 12, 2002
It might be worth mentioning that not all web-host support server side scripting.
A891506 - Use PHP to get a random background colour for a website
xyroth Posted Dec 13, 2002
while I don't see anything particularly wrong with the article, I can't actually see any good reason why you would want to serve up random background colours.
it might make a good php tutorial (but I don't know the language well enough to tell if it does), but it does seem rather a pointless thing to do.
considering just about all of the external links are to the php website, wouldn't it be better to try and get the tutorial added there?
A891506 - Use PHP to get a random background colour for a website
The Researcher formally known as Dr St Justin Posted Dec 22, 2002
True, you might not want to serve up random background colours, but the same scripts could be used for random colouring of *any* html entity, if you so wanted.
A891506 - Use PHP to get a random background colour for a website
Tango Posted Dec 22, 2002
Nice entry, well done! You might want to mention about not all servers using PHP in the last para as well, as a disadvantage, at the moment it is a very one sided comparision.
Tango
A891506 - Use PHP to get a random background colour for a website
The Guy With The Brown Hat Posted Dec 23, 2002
Maybe I'm being pedantic here, but for example 2b, wouldn't it make more sense to put all the colour values in an array to start off with, rather than assigning them to individual variables and then stuffing them in the array.
For example:
<?php
$colours = array( 1 =>
"#ffffff",
"#ffff99",
"#00ccff",
"#66ff99",
"#ffcc00",
"#d7ebff",
"#ccffcc");
$max = count($colours);
$number= rand(1,$max);
$bgcolour = $colours[$number];
echo ("");
?>
(Btw in your 2b, $bgcolour still uses the 2a-style $cN assignment. I'm guessing this was just a typo!)
A891506 - Use PHP to get a random background colour for a website
R'win Posted Dec 30, 2002
It wasn't a typo, and it works, but now that you mention it the array could have been used a bit more than it was.
Still it does what it's supposed to...
A891506 - Use PHP to get a random background colour for a website
R'win Posted Dec 30, 2002
It can actually be used to do random *anything* not just colours, it would just need a little editing...
A891506 - Use PHP to get a random background colour for a website
R'win Posted Dec 30, 2002
Tango, good point. I'll add that as a disadvantage
A891506 - Use PHP to get a random background colour for a website
The Guy With The Brown Hat Posted Dec 30, 2002
Ok .. but if it wasn't a typo, then there is absolutely no point in having the array there. It adds confusion.
You've written a nice introduction to showing people how to integrate PHP into a webpage - but I really think you should tidy the code up a bit.
A891506 - Use PHP to get a random background colour for a website
R'win Posted Dec 30, 2002
The array is used to find the number of colours for the upper limit of rand(). Had I thought at the time I could have used the array to find a random entry in it, but I don't see anything wrong with how it is at the moment
A891506 - Use PHP to get a random background colour for a website
The Guy With The Brown Hat Posted Dec 30, 2002
It's still a waste of an array - after the while loop has terminated, the upper limit is ($n-1)
A891506 - Use PHP to get a random background colour for a website
Mikey the Humming Mouse - A3938628 Learn More About the Edited Guide! Posted Feb 28, 2003
Although you say that the entry assumed the reader knows something about PHP already, I really think your first paragraph should have at least a sentence or two explaining what PHP is, what the letters stand for, etc.
A891506 - Use PHP to get a random background colour for a website
R'win Posted Feb 28, 2003
Good point.
I've quoted such a passage from http://www.php.net
Congratulations - Your Entry has been Picked for the Edited Guide!
h2g2 auto-messages Posted Apr 11, 2003
Your Guide Entry has just been picked from Peer Review by one of our Scouts, and is now heading off into the Editorial Process, which ends with publication in the Edited Guide. We've therefore moved this Review Conversation out of Peer Review and to the entry itself.
If you'd like to know what happens now, check out the page on 'What Happens after your Entry has been Recommended?' at EditedGuide-Process. We hope this explains everything.
Thanks for contributing to the Edited Guide!
Congratulations - Your Entry has been Picked for the Edited Guide!
Spelugx the Beige, Wizard, Perl, Thaumatologically Challenged Posted Apr 11, 2003
Key: Complain about this post
- 1
- 2
Peer Review: A891506 - Use PHP to get a random background colour for a website
- 1: R'win (Dec 4, 2002)
- 2: There is only one thing worse than being Gosho, and that is not being Gosho (Dec 4, 2002)
- 3: R'win (Dec 4, 2002)
- 4: HappyDude (Dec 12, 2002)
- 5: HappyDude (Dec 12, 2002)
- 6: xyroth (Dec 13, 2002)
- 7: The Researcher formally known as Dr St Justin (Dec 22, 2002)
- 8: Tango (Dec 22, 2002)
- 9: The Guy With The Brown Hat (Dec 23, 2002)
- 10: R'win (Dec 30, 2002)
- 11: R'win (Dec 30, 2002)
- 12: R'win (Dec 30, 2002)
- 13: The Guy With The Brown Hat (Dec 30, 2002)
- 14: R'win (Dec 30, 2002)
- 15: The Guy With The Brown Hat (Dec 30, 2002)
- 16: Mikey the Humming Mouse - A3938628 Learn More About the Edited Guide! (Feb 28, 2003)
- 17: R'win (Feb 28, 2003)
- 18: h2g2 auto-messages (Apr 11, 2003)
- 19: Spelugx the Beige, Wizard, Perl, Thaumatologically Challenged (Apr 11, 2003)
- 20: Tango (Apr 11, 2003)
More Conversations for Use PHP to get a random background colour for a website
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."