Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Daily Quote Script Re: PHP Daily Quote Script

#67083
gno
Member

Bob is spot on. There’s no need for such complicated code.

Is it really necessary to make it change each day? If its really important, to have it change each day, I imagine that it would require something else than a random choice too.

So, if its not crucial to have it change every 24 hours, then you could just get a random quote each time. Fx. by getting all the id’s of the quotes from your database, then selecting a random number from the range lowest-id -> max-id and then getting the quote related to that id.

Or, you could add a column to your database, containing a date. Your script should then first look for a quote with the current date- if there is no result (the first request that day) it should select a random quote, and then save the current day in the new column. You could make it only choose from quotes which have not been shown for a week if you desire to.

Both possibilities are a lot simpler than the one you suggest, and a little more complicated than the switch-case solution Bob suggested. Choose whatever makes the most sense to use in your project.