Posted By

scopefragger on 08/31/09


Tagged

random quotes rand


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

maxvee8
umang_nine
scopefragger


Random quote's


 / Published in: PHP
 

URL: http://www.scopesden.co.uk/code_get_feed.php?Content_ref=3

Sometimes it’s necessary to display a random quote or have a constantly changing image. This is quite simple in php and can be acheavedin a few lines. The code above works without the requirements of external hosts or scripts.

To set he number of quotes you wish to have in our loop simply change the second number next to $setquote. In our example, $setquote = rand(1,5), was used. In that wase the code can output different examples. If we wished to output 6 the could would look alike, $setquote = rand(1,6). For each quote the following line is required, else if ($setquote==5){$quote= "Yor fifth quote";} The value next to $set_quote should be increased on each new line.

  1. //Change the value of the second number
  2. //to match the number of quotes or statments
  3. //You wish to include.
  4. $set_quote = rand(1,5);
  5.  
  6. //Change the txt inbetween the brackets to your own
  7. //comments, statments or quotes
  8. if ($set_quote==1){$quote="Yor first quote";}
  9. else if ($set_quote==2){$quote= "Yor second quote";}
  10. else if ($set_quote==3){$quote= "Yor third quote";}
  11. else if ($set_quote==4){$quote= "Yor fourth quote";}
  12. else if ($set_quote==5){$quote= "Yor fifth quote";}
  13.  
  14. //To add another quote simply add the following line
  15. //changing the number after $set_quote to one larger than the previos line
  16. //Ie $set_quote==5,$set_quote==6,$set_quote==7,$set_quote==8....
  17. else if ($set_quote==6){$quote= "Yor number quote";}
  18. //The next line outputs the quote and requres no change
  19.  
  20. echo $quote;
  21. //

Report this snippet  

You need to login to post a comment.