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

Recommended Answers

All 8 Replies

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

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

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.

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

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.

**hi guys,
i m not able to execute this code.
mai i get a complete code for this..

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

It is complete, what's the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.