0

Hi Guys,
I want to be generating random quote of the day.
I want it to be so random and not repeating itself the same quote
What is the trick (If code exclude simple db stuffs like mysql_connect et al)

Thanks

4
Contributors
8
Replies
13
Views
7 Years
Discussion Span
Last Post by pritaeas
1

Hi Guys,
I want to be generating random quote of the day.
I want it to be so random and not repeating itself the same quote
What is the trick (If code exclude simple db stuffs like mysql_connect et al)

Thanks

refer this.http://www.jonasjohn.de/snippets/php/daily-random-quotes.htm just look at this

function RandomQuoteByInterval($TimeBase, $QuotesArray){
 
    // Make sure it is a integer
    $TimeBase = intval($TimeBase);
 
    // How many items are in the array?
    $ItemCount = count($QuotesArray);
 
    // By using the modulus operator we get a pseudo
    // random index position that is between zero and the
    // maximal value (ItemCount)
    $RandomIndexPos = ($TimeBase % $ItemCount);
 
    // Now return the random array element
    return $QuotesArray[$RandomIndexPos];
}

example

// Use the day of the year to get a daily changing
// quote changing (z = 0 till 365)
$DayOfTheYear = date('z'); 
 
// You could also use:
//  --> date('m'); // Quote changes every month
//  --> date('h'); // Quote changes every hour
//  --> date('i'); // Quote changes every minute
 
// Example array with some random quotes
$RandomQuotes = array(
    'No animals were harmed in the making of this snippet.',
    'Nice snippets',
    'The modulus operator rocks!',
    'PHP is cool.'
);
 
print RandomQuoteByInterval($DayOfTheYear, $RandomQuotes);
 
// --> returns "PHP is cool." on September 25, 2007
0

Thanks, I will implents it once I reach at home.
Thanks

Please mark solved problems, solved . it will help a lot to others. may be once again need this code in future to us.

0

Have you tested it? I can mark it if you testify. Otherwise I need to go and test and re-post the problem if any
Hope you understand what I mean

0

Have you tested it? I can mark it if you testify. Otherwise I need to go and test and re-post the problem if any
Hope you understand what I mean

ya......i already used this code. working fine.

0

i m not able to execute this code.
mai i get a complete code for this..

It is complete, what's the problem?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.