Grazie di vero cuore per il supporto che mi stai fornendo,
volevo, solo comprendere con un esempio come e cosa scrivere nel
Poi ti aggiorno sul risultato,codice:while($data = ???
nell'attesa di una risposta e per correttezza nei riguardi di chi leggerà il post dopo di noi e che magari avrà lo stesso problema, lascio la soluzione "assurda" che ho utilizzato io, la quale però mi ha permesso di ottenere il risultato che mi serviva.
Naturalmente è una soluzione temporanea, questo perchè vorrei poter implementare il tuo script e ridurre tutto il codice...
Codice PHP:
<?php
/*SCRIVO LA QUERY per GENNAIO*/
$gennaio16 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2016-01-01') AND ('2016-01-31')";
$rs_gennaio16 = $mysqli->query($gennaio16);
$fatt_gennaio16 = mysqli_fetch_assoc($rs_gennaio16);
$gennaio17 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2017-01-01') AND ('2017-01-31')";
$rs_gennaio17 = $mysqli->query($gennaio17);
$fatt_gennaio17 = mysqli_fetch_assoc($rs_gennaio17);
$gennaio18 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2018-01-01') AND ('2018-01-31')";
$rs_gennaio18 = $mysqli->query($gennaio18);
$fatt_gennaio18 = mysqli_fetch_assoc($rs_gennaio18);
$gennaio19 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2019-01-01') AND ('2019-01-31')";
$rs_gennaio19 = $mysqli->query($gennaio19);
$fatt_gennaio19 = mysqli_fetch_assoc($rs_gennaio19);
$gennaio20 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2020-01-01') AND ('2020-01-31')";
$rs_gennaio20 = $mysqli->query($gennaio20);
$fatt_gennaio20 = mysqli_fetch_assoc($rs_gennaio20);
/*SCRIVO LA QUERY per FEBBRAIO*/
$febbraio16 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2016-02-01') AND ('2016-02-31')";
$rs_febbraio16 = $mysqli->query($febbraio16);
$fatt_febbraio16 = mysqli_fetch_assoc($rs_febbraio16);
$febbraio17 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2017-02-01') AND ('2017-02-31')";
$rs_febbraio17 = $mysqli->query($febbraio17);
$fatt_febbraio17 = mysqli_fetch_assoc($rs_febbraio17);
$febbraio18 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2018-02-01') AND ('2018-02-31')";
$rs_febbraio18 = $mysqli->query($febbraio18);
$fatt_febbraio18 = mysqli_fetch_assoc($rs_febbraio18);
$febbraio19 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2019-02-01') AND ('2019-02-31')";
$rs_febbraio19 = $mysqli->query($febbraio19);
$fatt_febbraio19 = mysqli_fetch_assoc($rs_febbraio19);
$febbraio20 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2020-02-01') AND ('2020-02-31')";
$rs_febbraio20 = $mysqli->query($febbraio20);
$fatt_febbraio20 = mysqli_fetch_assoc($rs_febbraio20);
/*SCRIVO LA QUERY per MARZO*/
$marzo16 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2016-03-01') AND ('2016-03-31')";
$rs_marzo16 = $mysqli->query($marzo16);
$fatt_marzo16 = mysqli_fetch_assoc($rs_marzo16);
$marzo17 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2017-03-01') AND ('2017-03-31')";
$rs_marzo17 = $mysqli->query($marzo17);
$fatt_marzo17 = mysqli_fetch_assoc($rs_marzo17);
$marzo18 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2018-03-01') AND ('2018-03-31')";
$rs_marzo18 = $mysqli->query($marzo18);
$fatt_marzo18 = mysqli_fetch_assoc($rs_marzo18);
$marzo19 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2019-03-01') AND ('2019-03-31')";
$rs_marzo19 = $mysqli->query($marzo19);
$fatt_marzo19 = mysqli_fetch_assoc($rs_marzo19);
$marzo20 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2020-03-01') AND ('2020-03-31')";
$rs_marzo20 = $mysqli->query($marzo20);
$fatt_marzo20 = mysqli_fetch_assoc($rs_marzo20);
/*SCRIVO LA QUERY per APRILE*/
ecc ecc
/*CALCOLO I TOTALI*/
$totale16 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2016-01-01') AND ('2016-12-31')";
$totale_2016 = $mysqli->query($totale16);
$totale_anno16 = mysqli_fetch_assoc($totale_2016);
/*SCRIVO LA QUERY per FEBBRAIO*/
$totale17 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2017-01-01') AND ('2017-12-31')";
$totale_2017 = $mysqli->query($totale17);
$totale_anno17 = mysqli_fetch_assoc($totale_2017);
/*SCRIVO LA QUERY per MARZO*/
$totale18 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2018-01-01') AND ('2018-12-31')";
$totale_2018 = $mysqli->query($totale18);
$totale_anno18 = mysqli_fetch_assoc($totale_2018);
/*SCRIVO LA QUERY per APRILE*/
$totale19 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2019-01-01') AND ('2019-12-31')";
$totale_2019 = $mysqli->query($totale19);
$totale_anno19 = mysqli_fetch_assoc($totale_2019);
/*SCRIVO LA QUERY per MAGGIO*/
$totale20 = "SELECT SUM(totale) FROM commesse WHERE data BETWEEN ('2020-01-01') AND ('2020-12-31')";
$totale_2020 = $mysqli->query($totale20);
$totale_anno20 = mysqli_fetch_assoc($totale_2020);
?>
<style>
.container-menu-superiore{
background-color:#F2F2F2;
padding: 10px;
text-align:center;
width: 100%;
margin:15px;
}
</style>
<div class = "container-menu-superiore">
<div class ="row">
<div class="col-sm-3">
</div>
<div class="col-sm-3">
</div>
<div class="col-sm-3">
</div>
<div class="col-sm-3">
<button onclick="window.location.reload();" class="btn btn-outline-warning">Aggiorna la pagina</button>
</div>
</div>
</div>
<?php
echo"
<table class='table table-striped > fatturato'>
<thead>
<tr>
<th scope='col'></th>
<th class='text-center > intestazione_fatturato' scope='col'>
Incasso<br>
2016
</th>
<th class='text-center > intestazione_fatturato' scope='col'>
Incasso<br>
2017
</th>
<th class='text-center > intestazione_fatturato' scope='col'>
Incasso<br>
2018
</th>
<th class='text-center > intestazione_fatturato' scope='col'>
Incasso<br>
2019
</th>
<th class='text-center > intestazione_fatturato' scope='col'>
Incasso<br>
2020
</th>
</tr>
</thead>
<tbody>
<tr>
<th class='text-nowrap' scope='row'>Gennaio</th>
<td>€ {$fatt_gennaio16['SUM(totale)']}</td>
<td>€ {$fatt_gennaio17['SUM(totale)']}</td>
<td>€ {$fatt_gennaio18['SUM(totale)']}</td>
<td>€ {$fatt_gennaio19['SUM(totale)']}</td>
<td>€ {$fatt_gennaio20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Febbraio</th>
<td>€ {$fatt_febbraio16['SUM(totale)']}</td>
<td>€ {$fatt_febbraio17['SUM(totale)']}</td>
<td>€ {$fatt_febbraio18['SUM(totale)']}</td>
<td>€ {$fatt_febbraio19['SUM(totale)']}</td>
<td>€ {$fatt_febbraio20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Marzo</th>
<td>€ {$fatt_marzo16['SUM(totale)']}</td>
<td>€ {$fatt_marzo17['SUM(totale)']}</td>
<td>€ {$fatt_marzo18['SUM(totale)']}</td>
<td>€ {$fatt_marzo19['SUM(totale)']}</td>
<td>€ {$fatt_marzo20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Aprile</th>
<td>€ {$fatt_aprile16['SUM(totale)']}</td>
<td>€ {$fatt_aprile17['SUM(totale)']}</td>
<td>€ {$fatt_aprile18['SUM(totale)']}</td>
<td>€ {$fatt_aprile19['SUM(totale)']}</td>
<td>€ {$fatt_aprile20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Maggio</th>
<td>€ {$fatt_maggio16['SUM(totale)']}</td>
<td>€ {$fatt_maggio17['SUM(totale)']}</td>
<td>€ {$fatt_maggio18['SUM(totale)']}</td>
<td>€ {$fatt_maggio19['SUM(totale)']}</td>
<td>€ {$fatt_maggio20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Giugno</th>
<td>€ {$fatt_giugno16['SUM(totale)']}</td>
<td>€ {$fatt_giugno17['SUM(totale)']}</td>
<td>€ {$fatt_giugno18['SUM(totale)']}</td>
<td>€ {$fatt_giugno19['SUM(totale)']}</td>
<td>€ {$fatt_giugno20['SUM(totale)']}</td>
</tr>
<tr>
<th class='text-nowrap' scope='row'>Luglio</th>
<td>€ {$fatt_luglio16['SUM(totale)']}</td>
<td>€ {$fatt_luglio17['SUM(totale)']}</td>
<td>€ {$fatt_luglio18['SUM(totale)']}</td>
<td>€ {$fatt_luglio19['SUM(totale)']}</td>
<td>€ {$fatt_luglio20['SUM(totale)']}</td>
</tr>
<th class='text-nowrap' scope='row'>Agosto</th>
<td>€ {$fatt_agosto16['SUM(totale)']}</td>
<td>€ {$fatt_agosto17['SUM(totale)']}</td>
<td>€ {$fatt_agosto18['SUM(totale)']}</td>
<td>€ {$fatt_agosto19['SUM(totale)']}</td>
<td>€ {$fatt_agosto20['SUM(totale)']}</td>
</tr>
<th class='text-nowrap' scope='row'>Settembre</th>
<td>€ {$fatt_settembre16['SUM(totale)']}</td>
<td>€ {$fatt_settembre17['SUM(totale)']}</td>
<td>€ {$fatt_settembre18['SUM(totale)']}</td>
<td>€ {$fatt_settembre19['SUM(totale)']}</td>
<td>€ {$fatt_settembre20['SUM(totale)']}</td>
</tr>
<th class='text-nowrap' scope='row'>Ottobre</th>
<td>€ {$fatt_ottobre16['SUM(totale)']}</td>
<td>€ {$fatt_ottobre17['SUM(totale)']}</td>
<td>€ {$fatt_ottobre18['SUM(totale)']}</td>
<td>€ {$fatt_ottobre19['SUM(totale)']}</td>
<td>€ {$fatt_ottobre20['SUM(totale)']}</td>
</tr>
<th class='text-nowrap' scope='row'>Novembre</th>
<td>€ {$fatt_novembre16['SUM(totale)']}</td>
<td>€ {$fatt_novembre17['SUM(totale)']}</td>
<td>€ {$fatt_novembre18['SUM(totale)']}</td>
<td>€ {$fatt_novembre19['SUM(totale)']}</td>
<td>€ {$fatt_novembre20['SUM(totale)']}</td>
</tr>
<th class='text-nowrap' scope='row'>Dicembre</th>
<td>€ {$fatt_dicembre16['SUM(totale)']}</td>
<td>€ {$fatt_dicembre17['SUM(totale)']}</td>
<td>€ {$fatt_dicembre18['SUM(totale)']}</td>
<td>€ {$fatt_dicembre19['SUM(totale)']}</td>
<td>€ {$fatt_dicembre20['SUM(totale)']}</td>
</tr>
<tr style='color:green; font-weight: bold;'>
<th class='text-nowrap' scope='row'>Totale</th>
<td>€ {$totale_anno16['SUM(totale)']}</td>
<td>€ {$totale_anno17['SUM(totale)']}</td>
<td>€ {$totale_anno18['SUM(totale)']}</td>
<td>€ {$totale_anno19['SUM(totale)']}</td>
<td>€ {$totale_anno20['SUM(totale)']}</td>
</tr>
</tbody>";
echo"</table>";
?>
Grazie ancora