RWE
RWE

Reputation: 15

Create daily offer

So i'm trying to create a daily offer for my exam project - The idea is to extract information from my DB and make some kind of random function that calls out a random product each day, but for now i'm pretty much stuck nowhere.

Any great guides or solutions?

Upvotes: 0

Views: 62

Answers (1)

roberto06
roberto06

Reputation: 3864

Here's how you could do it :

  1. Create a SQL table which will store your daily product (two columns id_product and date should suffice) -- let's call it daily_products
  2. Create a PHP script which will select the product id for today's date from daily_products
    • If there is none, do an SQL request on your products table which will return only one line with an ORDER BY RAND(), then store the product id and today's date in daily_products
    • If there is one, do nothing
  3. Call this PHP script daily
    • Either with a cronjob which will execute every day, say at 00:01
    • Or on the first daily visit of your website (in this case, it should be called before your website rendering)

Upvotes: 1

Related Questions