01/04/11 8:31
Sici
Salve a tutti sono nuovo del forum...volevo chiedervi come faccio a fare la somma di tutti i campi importo_entrata dalla tabella entrate e sottrarlo alla somma di tutti i campi importo_uscita dalla tabella uscite
ho provato con la seguente query:
ma mi restituisce un risultato sballato
questo è tutto il codice della pagina php:
-------------------------------------------------------------------------------
ho provato con la seguente query:
$query1 = "SELECT sum(importo_entrata)-sum(importo_uscita) as fondo_cassa FROM entrate, uscite";
ma mi restituisce un risultato sballato
questo è tutto il codice della pagina php:
-------------------------------------------------------------------------------
<?php include("config.inc.php"); $query1 = "SELECT sum(importo_entrata)-sum(importo_uscita) as fondo_cassa FROM entrate, uscite"; $query2 = "SELECT * FROM entrate"; $query3 = "SELECT * FROM uscite"; // Richiesta $exquery1 = mysql_query($query1,$db) or die("Errore nell'estrazione dei dati1"); $exquery2 = mysql_query($query2,$db) or die("Errore nell'estrazione dei dati2"); $exquery3 = mysql_query($query3,$db) or die("Errore nell'estrazione dei dati3"); // Esecuzione della query2 echo "<br> <table border=2> <tr> <td width=130> Entrata </td> <td width=80> Data Entrata </td> <td width=150> Motivazione </td> </tr> </table>"; while($row = mysql_fetch_array($exquery2)){ echo "<table border=2> <tr> <td width=130> $row[importo_entrata] </td> <td width=80> $row[data_entrata] </td> <td width=150> $row[motivazione_entrata] </td> </tr> </table>"; } // Esecuzione della query echo "<br><table border=2> <tr> <td width=130> Uscita </td> <td width=80> Data Uscita </td> <td width=150> Motivazione</td> </tr> </table>"; while($row = mysql_fetch_array($exquery3)){ echo "<table border=2> <tr> <td width=130> $row[importo_uscita] </td> <td width=80> $row[data_uscita] </td> <td width=150> $row[motivazione_uscita] </td> </tr> </table>"; } // Esecuzione della query1 echo "<br><table border=2> <tr> <td width=130> Fondo Cassa </td> <td width=80> Data </td> </tr> </table>"; while($row = mysql_fetch_array($exquery1)){ echo "<table border=2> <tr> <td width=130> $row[fondo_cassa] </td> </tr> </table>"; } mysql_close($db); echo "<a href=\"Movimenti.html\">Torna ai movimenti</a>"; ?>
aaa