Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,473
There are 1917 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Code to display DAILY random string?

Thread title: Code to display DAILY random string?
Reply  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
10-18-2009, 05:43 PM
#1
Kryptonix is offline Kryptonix
Status: Junior Member
Join date: Nov 2005
Location:
Expertise:
Software:
 
Posts: 26
iTrader: 0 / 0%
 

Kryptonix is on a distinguished road

  Old  Code to display DAILY random string?

Hi guys, I've got a script that will display a random quote each time the page is visited or refreshed, but I'd like to have something that will pick a random string from a list and display it for the entire day...is this possible? Thanks!

Reply With Quote
10-18-2009, 06:13 PM
#2
Jeff Andersen is offline Jeff Andersen
Status: Superstar
Join date: Apr 2005
Location:
Expertise:
Software:
 
Posts: 4,449
iTrader: 10 / 100%
 

Jeff Andersen is on a distinguished road

  Old

What I'd probably do is have a database table with all my quotes, then have a cron job that runs every day at midnight and updates a value in my database specifying what quote to display.

So the cron job would run the randomizing script and a quick query to set that value.

Otherwise if you leave it to cookies or some sort of dynamically ran script you're gonna have more places for failure.

Regards,

*edit* Hell, you could even do it all via flat files if you don't have database access.

Reply With Quote
10-18-2009, 06:46 PM
#3
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

Yep cron is your friend here!

Reply With Quote
10-18-2009, 08:02 PM
#4
Kryptonix is offline Kryptonix
Status: Junior Member
Join date: Nov 2005
Location:
Expertise:
Software:
 
Posts: 26
iTrader: 0 / 0%
 

Kryptonix is on a distinguished road

  Old

I found this code online, but I'm not sure how to use it?

Code:
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];
}

Reply With Quote
10-18-2009, 09:02 PM
#5
Jeff Andersen is offline Jeff Andersen
Status: Superstar
Join date: Apr 2005
Location:
Expertise:
Software:
 
Posts: 4,449
iTrader: 10 / 100%
 

Jeff Andersen is on a distinguished road

  Old

I'd need more context as to how that's being applied but my thoughts are that's gonna give every visitor a different quote per day.. so if I go to Tom and say "Hey check out the daily quote" he'll see a different one and have no idea what I'm talking about.

Reply With Quote
10-18-2009, 09:14 PM
#6
46Bit is offline 46Bit
Status: Member
Join date: Mar 2009
Location: Yorkshire
Expertise: Web Development
Software:
 
Posts: 275
iTrader: 10 / 100%
 

46Bit is on a distinguished road

Send a message via MSN to 46Bit Send a message via Skype™ to 46Bit

  Old

Just hire Jeff to do this if you don't know any PHP, it'll only take an hour or two to make and test but you can't really expect us to do you a whole php script/mysql db/cronjob for free.

If you do know it, a simpler version could as he mentioned be created using text or xml files, pretty obvious how to sort that if you do...

Reply With Quote
10-18-2009, 09:15 PM
#7
Kryptonix is offline Kryptonix
Status: Junior Member
Join date: Nov 2005
Location:
Expertise:
Software:
 
Posts: 26
iTrader: 0 / 0%
 

Kryptonix is on a distinguished road

  Old

No worries, I figured it out. Cronjob completely unnecessary.

Reply With Quote
10-18-2009, 11:32 PM
#8
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

How did you do it? If you don't mind me asking..! (I'm always up for hearing other peoples' methods!)

Reply With Quote
10-19-2009, 03:02 AM
#9
Kryptonix is offline Kryptonix
Status: Junior Member
Join date: Nov 2005
Location:
Expertise:
Software:
 
Posts: 26
iTrader: 0 / 0%
 

Kryptonix is on a distinguished road

  Old

That code works perfectly. I was just having a massive brain fart on PHP arrays.

Reply With Quote
10-29-2009, 04:56 PM
#10
Orny is offline Orny
Status: I'm new around here
Join date: Oct 2009
Location: Israel
Expertise:
Software:
 
Posts: 11
iTrader: 0 / 0%
 

Orny is on a distinguished road

Send a message via MSN to Orny

  Old

I think an array of quotes and php date() will do the job.

Reply With Quote
Reply  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed