Jump to content

Recommended Posts

Hi,

 

What I want is that in the jokes section of site, I want a jokes to appear daily (today's Joke)

 

Whats the best way to do that.

 

Would it be better if there is a link to Today's Joke & it pops up after clicking it, or its better that it takes you to the

jokes page and displays it there.?

 

Thanks in advance for any help.

 

EG

Link to comment
https://forums.phpfreaks.com/topic/43347-randomly-generating-a-joke/
Share on other sites

<?php
session_start();
$number = rand(1,5);

if ($numb = 1){
echo "First Joke";}

elseif ($numb = 2){
echo "Second Joke";}

elseif ($numb = 3){
echo "Third Joke";}


elseif ($numb = 4){
echo "Fourth Joke";}

elseif ($numb = 5){
echo "Fith Joke";}

?>

 

 

 

 

 

Errr...is it possible to have a file with jokes, say 100 in it.

and then have the jokes generated from it, new one each day?? ???

 

what i would do is make a fuile called jokes.txt and then use the fopen method to read the file line by line, that would then be loaded into an array that would have a random calling depending on the amount of jokes in the array i.e. rand(0,$jokes_in_array).

 

that way yu can easly add more jokes, and they will always be random :)

 

the more you have the more random it will be!

The first step i ever took in the php world was this exact problem:

 

http://www.sitepoint.com/article/php-amp-mysql-1-installation/1

 

that book should tell you how to do it with a database if you want, or i have alot of documentation on the fopen method, or failing that read about it at www.php.net. Good luck!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.