query by the number of the day of the week Mysql

3

The week has 7 days, so I want to be able to make an appointment depending on the day of the week you choose to show the result:

mysql_query("SELECT * FROM tbl_eventos WHERE WEEK(data) = '$semana_atual' AND YEAR(data) = '$ano_atual'");

Now in this query, I want to try to fit the day of the week ( $dia_semana ) from 1 to 7 and so all the events of that day of the week, the week and the current year are presented.

That is, if you choose the day of week 4, it will list the events of day of week 4, which corresponds to Wednesday.

    
asked by anonymous 11.02.2015 / 16:31

1 answer

1

Use the DAYOFWEEK function in the data column. It returns the index of the day of the week, with 1 being Sunday, 2 being Monday and thereafter.

Source: MySQL documentation

    
11.02.2015 / 16:37