I have a MySql database in which I keep activities with the following structure.
id (int) | nombre(varchar) | descripcion(text) | mes(tinyint)
What I'm trying to get is to show in php a list of them from the current month.
Until now I solved it by doing 2 separate consultations and then repeating the results consecutively in html ...
$mesactual = date("m")-1;
.php
$stm = $pdo -> prepare("SELECT * FROM actividades WHERE mes >= $mesactual ORDER BY mes");
$stm -> execute();
$resultado = $stm -> fetchAll();
$stm = $pdo -> prepare("SELECT * FROM actividades WHERE mes < $mesactual ORDER BY mes");
$stm -> execute();
$resultado2 = $stm -> fetchAll();
.html
foreach ($resultado as $item){
...
}
foreach ($resultado2 as $item){
...
}
Is there any way to unify in a single query?