I have a field date, would like to make a query to take only the month of this field. How can I do that?
Well this... But my problem is not this, I want to make a variable in php that receives this value and sort by this variable... understand?
– Diogo Silva
Make your
query
and at the end put the followingODER BY MONTH(seu_campo)
.– Roberto de Campos
It doesn’t solve... wanted something but rather $query = "SELECT * FROM table ORDER BY MONTH(field, $variable)". Understand?
– Diogo Silva
So what you want is to list only the lines in that field
date
corresponds to the month of its variable inPHP
?– Roberto de Campos
That buddy... got to do it?
– Diogo Silva
You can simplify the operation by doing the processing in select and using an internal query variable for the clauses WHERE and ORDER: SELECT MONTH(date) AS mes FROM table WHERE mes = '$variable' ORDER BY mes
– Evandro Klimpel Balmant
So your
query
would look like thisSELECT * FROM tabela WHERE MONTH(seu_campo) = $variavel
.– Roberto de Campos