Random Style - PHP & MySQL tutorial
- Added: Aug 17th, 2006
- Level: Easy
- Author: hp
- Reads: 12,005
- Description: Learn a quick way to use a random CSS for your layouts.
This is a very simple tutorial which requires almost no PHP knowledge. Few days back, I made a code for random quotes. Then I figured out that instead of random Quotes why donít use random Styles? Itís just easy as saying cool.
Proceeding with the tutorial. In this tutorial, you will need two or more CSS files. For example, I have two CSS files and I need to change the style of my web site randomly. Letís name the first file as greenstyle.css and bluestyle.css.
Now, create a new txt file and add this code to it:
<link rel="stylesheet" type="text/css" href="greenstyle.css">
<link rel="stylesheet" type="text/css" href="bluestyle.css">
Now the explanation:
The first line of the code generates a style named greenstyle.css. The second line is just a command I used for separating the codes. And finally, the third line, in the line, I have given him the code of bluestyle.css so that it can generate a style in between the two styles.
Now save the txt file as randomlayout.txt and upload it to the directory of header.php file or whatever you named it.
PHP time now. You have to do nothing just add the following code to the header of each page or to the header.php file:
echo $arry_txt[rand(0,sizeof($arry_txt)-1)]; ?>
Just put the code in header.php file and then you are done.
Donít know whatís header.php? check out the php includes tutorial for more information.
Please remember to replace you current .CSS code with the PHP code. Or, the tutorial may not function.
Have a good day.
Tutorial © hp. Do not reproduce in any way without previous permission from the author.