Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

Adding a Message Of the Day or Quote of the Day to your system

Adding a Message Of the Day or Quote of the Day to your system

Got handed a nice SQL file a few years back, one which I slip into most of my applications and one that generates quotes of the day, (or Message of the day – MOTD) there are 1462 records or about 4 years worth of quotes on there if you generate one per day. The SQL Create file for the table is zipped here => qotd

To load the quotes, simply unzip and run the query on your SQL system, this will generate the qotd table with 2 fields in it (don’t worry, nothing too rude or controversial and its only a 100KB or so)

There are several ways to use it, here is the simplest:

SELECT quote 
FROM qotd
WHERE uid = ( TO_DAYS(NOW()) MOD (SELECT COUNT(*) FROM qotd) )

Tested only on MySQL which is sometimes a bit quirky, but Hopefully your chosen SQL system supports the above, for explanation,

  • The MOD function is simply the remainder when you divide the first parameter by the second, eg 7 mod 5 =   2. (same as % in C)
  • The TO_DAYS(date) function returns the day as an integer:

ie SELECT TO_DAYS(NOW()) returned 736255 on the 19 October 2015

  • (SELECT COUNT(*) FROM qotd) is a sub-query which returns the number of quotes in the table (the number of records) and returns 1462

So the where function simply returns 736255 % 1462 and selects the quote where uid = 869, once the date gets to quote 1462 it will go back to quote 1 and keep on going. If you add more quotes it will also automatically include them.

Enjoy

Read more Here







 

More Articles to Read

App note: EPIC: Electro-Pyrotechnic Initiator Chip Resistor
App note: EPIC: Electro-Pyrotechnic Initiator Chip Resistor
App note: Noise analysis for high-speed op amps
App note: Noise analysis for high-speed op amps
Skill Sunday: Arrays
Skill Sunday: Arrays
App note: Infrared remote control implementation with MSP430FR4xx
App note: Infrared remote control implementation with MSP430FR4xx
Gesture Controlled Smart Home
Gesture Controlled Smart Home
Design for a Wideband, Differential Transimpedance DAC Output
Design for a Wideband, Differential Transimpedance DAC Output
Wrist thrusters let you fly through the water effortlessly
Wrist thrusters let you fly through the water effortlessly
Bertan/Spellman 225-20R HV power supply teardown
Bertan/Spellman 225-20R HV power supply teardown
Blinking Christmas Lights
Blinking Christmas Lights
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adjusting clock with alarm, hygrometer & thermometer on 1.8″ ST7735 display
Adding an “extra sense” with rangefinders
Adding an “extra sense” with rangefinders
This wireless game controller looks like a rug
This wireless game controller looks like a rug
How to run your ESP8266 for years on a battery
How to run your ESP8266 for years on a battery
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Calibration of a 3-Phase Energy Meter Board on the ADE7754
Making beats on a tiny Arduino DJ controller
Making beats on a tiny Arduino DJ controller
Qinsi-QS5100 Sn63Pb37 solder profile
Qinsi-QS5100 Sn63Pb37 solder profile
Water Detection System
Water Detection System
Professional Hi-Fi 15W Tube Amplifier circuit
Professional Hi-Fi 15W Tube Amplifier circuit
This Arduino machine will judge how sick your ollies are
This Arduino machine will judge how sick your ollies are
Turn an old payphone into a boombox for ’90s hits
Turn an old payphone into a boombox for ’90s hits

Top


Shares