P
P
PaddingtonBaby2022-03-25 22:10:40
css
PaddingtonBaby, 2022-03-25 22:10:40

Is it possible to do an automatic quote of the day in pure PHP?

Hey! In the course of learning PHP, I set out to make an automatic display of the quote of the day on the screen.
I found a (very strange, as for me) code of the form:

if(date('d.m.Y') == '25.03.2022') {echo 'Цитата один';}
        else {
          if (date('d.m.Y') == '26.03.2022') {echo 'Цитата два';}
        } else {
if (date('d.m.Y') == '27.03.2022') {echo 'Цитата три';} }

Everyone understands that this hurdy-gurdy can continue until you turn blue, but it is also clear that it is somehow strange to enter the code conditionally every 7 days and enter new numbers there, and now I have two legitimate questions.
The first question: Do I understand correctly that I should link this case to a database, into which data will be written to the table through almost the same check and then selected on the site?
Question two: Will the code be constantly processed? -> How "harmful" is it to performance if I check mySQL with quote tables every time the page is refreshed?
If there are other concepts for performing a similar task - share your ideas, please! And I, in turn, will try to implement it as soon as possible to show the result :)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
Denis Bukreev, 2016-07-09
@denisbookreev

Block with three borders (no top, if anything)
Inside the element with :beforeand :after, which will make up the top border

H
HamSter, 2016-07-09
@HamSter007

1
2
3
4
5
6
...

A
alex921, 2016-07-09
@alex921

Thank you very much.

A
Andrey Fedorov, 2016-07-09
@aliencash

✩

P
pLavrenov, 2022-03-25
@PaddingtonBaby

How "harmful" is it to performance if I check mySQL with quote tables every time the page is updated?

Not by how much. One request is a tiny fraction of the time. Sites use dozens and hundreds of queries to generate a single page.
If there are other concepts for performing a similar task - share your ideas, please!

For example, you can make an array of the form "20220101" => "quote of the day" and immediately for a whole year ahead without obscurantism from if-else.
Do I understand correctly that I should bind this case to the database

Depends on how convenient you want to use it. The database is just a source of data that needs to be added there too. As a project for developing yourself as a programmer, it is worth using the base, this will give room for maneuvers. The next step could be writing a simple admin panel to add to the database or using PhpMyAdmin (or TablePlus, etc.) to work with the database. Such small tasks can be developed.

O
Oleg, 2022-03-26
@402d

read about the date() function
there is:
- day of the week
- day of the month
- day of the year
Create an array of the required number of quotes (7,31,366)
and you can forget about the task for several years

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question