Ipis tablice i zbrajanje ukupnog iznosa

Pozdrav,

imam sljedeće

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Poslovi</title>
</head>
<body>
<?php

include('config.php');

$result = mysql_query("SELECT * FROM poslovi")
or die(mysql_error());

echo "<table border='1' cellpadding='10'>";
echo "<tr>

<th><font color='Red'>Tvrtka/Klijent</font></th>
<th><font color='Red'>Kampanja</font></th>
<th><font color='Red'>Datum racuna</font></th>
<th><font color='Red'>Iznos racuna</font></th>
<th><font color='Red'>Uredi</font></th>
<th><font color='Red'>Obriši</font></th>
</tr>";

while($row = mysql_fetch_array( $result ))
{

echo "<tr>";

echo '<td><b><font color="#663300">' . $row['tvrtka'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['imekampanje'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['datumracuna'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['iznosracuna'] . '</font></b></td>';
echo '<td><b><font color="#663300"><a href="edit.php?id=' . $row['id'] . '">Edit</a></font></b></td>';
echo '<td><b><font color="#663300"><a href="delete.php?id=' . $row['id'] . '">Delete</a></font></b></td>';
echo "</tr>";

}

echo "</table>";
?>

<p><a href="insert.php">Dodaj novi</a></p>
</body>
</html>

Kako bi mogao dodati jedno polje gdje ce mi zbrojiti ukupan iznos računa?
Hvala unaprijed na pomoci.

Lp,
Ivan

Sorry sredio…

$result2 = mysql_query('SELECT iznosracuna FROM poslovi'); 
if (mysql_num_rows($result2) > 0) { 
 $sum = array(); // initialize 
 while ($myrow = mysql_fetch_array($result2)) { 
  $sum[] = $myrow['iznosracuna']; // sum 
  $iznosracuna= $myrow['iznosracuna']; 
 } 
 $sum = array_sum($sum); 
} else { 
 print "<h1>No results</h1>\n"; 
}
echo "<tr>
<th><font color='Red'>Ukupan iznos: $sum </font></th>
</tr>";

Možeš korisititi i query “SELECT SUM(cijena) AS ukupno FROM poslovi”.

još možeš i css ubacit da ti bude DRY


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja