phpbar.de logo

Mailinglisten-Archive

[php] summieren der keys im array

[php] summieren der keys im array

Boris Penck php_(at)_phpcenter.de
Fri, 25 May 2001 14:43:41 +0200


> $sql = 'select day as dat,sum(count) as pi,sum(visits) as vi from
> pageviews_archiv where day > from_days(to_days(curdate())-32) group by day
> order by day';
>
> $db->query($sql);
> echo "<table border=0 width=300><tr
> bgcolor=#999966>";
> echo "<td width=33%>Datum</td><td
> width=33%>Pi</td><td width=33%>Vi</td></tr>";
> echo "</table>";
>
> while($row = $db->fetch_array()) {
> echo "<table border=0 width=300><tr
> bgcolor=#ffffcc>";
> echo "<td width=33%>".$row["dat"]."</td>";
> echo "<td width=33%>".$row["pi"]."</td>";
> echo "<td width=33%>".$row["vi"]."</td>";
> echo "</tr></table>";
> }
> soweit so gut...jetzt möchte ich die summen der $row["pi"] und
> $row["vi"]...ausgerechnet und unter die tabelle einsetzen...kann mir
jemand
> einen tip geben...???

while($row = $db->fetch_array()) {
$pi += $row["pi"];
$vi += $row["vi"];
echo "<table border=0 width=300><tr
bgcolor=#ffffcc>";
echo "<td width=33%>".$row["dat"]."</td>";
echo "<td width=33%>".$row["pi"]."</td>";
echo "<td width=33%>".$row["vi"]."</td>";
echo "</tr></table>";
}

print "Total PI: ".$pi;
print "Total VI: ".$vi;






php::bar PHP Wiki   -   Listenarchive