sorgularını bu döngüde çalıştırırsan istediğin çıktıyı alırsın
for ($i=0; $i<6; $i++) {
if($i == 0){
echo date('Y-m-d')."\n";
}else{
echo date('Y-m-d', strtotime(date("Y-m-d",strtotime('first day of this month')).' - '.$i .' month'))."\n";
}
}Ekleme : verileri de şu şekilde alabilirsin
for ($i=0; $i<6; $i++) {
if($i == 0){
$yil = date('Y');
$ay = date('m');
}else{
$yil = date('Y', strtotime(date("Y-m-d",strtotime('first day of this month')).' - '.$i .' month'))."\n";
$ay = date('m', strtotime(date("Y-m-d",strtotime('first day of this month')).' - '.$i .' month'))."\n";
}
$query = $db->query("SELECT * FROM tablo WHERE MONTH(tarih) = '$ay' AND YEAR(tarih) = '$yil'", PDO::FETCH_ASSOC);
if ( $query->rowCount() ){ /* veriler*/}
}