Bank data for days of the week

0

I was thinking here and could not figure out the way this would work.

Let's suppose I have 1 database with 10 posts and in a column had "Day of the week"

ID | NOME | DIA DA SEMANA
-------------------------
1  | ALAN | SEGUNDA-FEIRA
2  | ALEX | QUINTA-FEIRA
3  | BIA  | SEGUNDA-FEIRA
4  | CAIO | SEXTA-FEIRA
5  | KAIO | TERÇA-FEIRA
6  | LANA | QUARTA-FEIRA
7  | LUAN | SEGUNDA-FEIRA
8  | EVA  | SÁBADO
9  | ADÃO | DOMINGO
10 | MELO | DOMINGO

And when it was Monday my database logs would appear on my home page, if Tuesday all Tuesday would appear on the homepage and so on.

Could someone explain me how this employee?

    
asked by anonymous 19.05.2017 / 22:50

2 answers

1

First, get today's date. Using date() , it generates the days in English (Sat, Sun, Mon ...), so I'll use an array to render:

<?php
    $data = date('D');   
    $semana = array(
        'Sun' => 'Domingo', 
        'Mon' => 'Segunda-Feira',
        'Tue' => 'Terca-Feira',
        'Wed' => 'Quarta-Feira',
        'Thu' => 'Quinta-Feira',
        'Fri' => 'Sexta-Feira',
        'Sat' => 'Sábado'
    );
$dia_semana = $semana["$data"]; ?>

Note: date('D') generates the date as day of the week as text. If you use lowercase, it will generate the day as a number.

Now it's simple, just SQL

$sql = "SELECT * FROM sua_tabela WHERE DIA_DA_SEMANA = '$dia_semana'";
    
19.05.2017 / 23:14
0

If I understood your question well, it would look like this:

# Para segunda:
SELECT * FROM tabela WHERE dia_da_semana = 'SEGUNDA-FEIRA'

# Para terça:
SELECT * FROM tabela WHERE dia_da_semana = 'SEGUNDA-FEIRA'

# E assim por diante...
    
19.05.2017 / 23:06