query by day number of Mysql week

Asked

Viewed 2,044 times

3

The week has 7 days, so I want to be able to make a query that the user according to the day of the week you choose presents the result:

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

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

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

  • Your question is regarding the SQL query or the user interface to choose the day of the week?

1 answer

1

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

Source: mysql documentation

  • This is not what I am looking for. I want to consult from the day of the week and not the other way around. Let’s say I want to pick up the day of week 4, he goes to the comic book to pick up all the events of the day of week 4

  • SELECT * WHERE DAYOFWEEK(sua_data) = 4. This?

  • That’s right, just put in the condition WHERE.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.