Buy Now
Sign in

Sum of Table Row`s

qwarx , November 04 2008, 10:18
Q
qwarx 5
November 04 2008, 10:18 #16521
Hi,
(my writen english in not the best so .... )

i want to correcty insert the syntax from my code in "Where SQL"
now i put the code into "footer" but this way i think is not correct

i want to summate columns like this (i post the completly code)
noting in "where sql"

header

statistik von spieler hans
{pagination}
<table border="0" width="300" cellspacing="0" cellpadding="0" id="table1">
  <tr>
<td>Tag</td>
    <td>Trainingszeiten</td>
    <td>Spielzeiten</td>
  </tr>


body

<tr>
<td>{cf_id}</td>
    <td>{text_0}</td>
    <td>{text_1}</td>
  </tr>


footer
<?php
$DBhost = "localhost";
$DBuser = "myusername";
$DBpass = "mypasswort";
$DBName = "mydbname";
$table = "jos_chronoforms_Spielerstatistik";
$sum1 = 0;
$sum2 = 0;
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db("$DBName") or die("Unable to select database $DBName");
$result = mysql_query("SELECT * FROM $table");
while ($row = mysql_fetch_row($result)) {
$sum1 += $row[5];
$sum2 += $row[6];
}
?>
<tr>
    <td>Gesamt</td>
    <td><?php print "$sum1"; ?></td>
    <td><?php print "$sum2"; ?></td>
</tr></table>


it works so far but i think the way is not correct and i want do the statement in "where sql" section

please help me
thank a lot

Andy
admin 28
November 04 2008, 14:21 #16538
Hi Andy,

try to write
<?php echo count($rows); ?>
any where in the header, body or footer and see if this works ?

Max
Max
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
Q
qwarx 5
November 04 2008, 15:16 #16547
first thanks a lot
but i think i ask false
i dont want count the rows and also not the calculation in footer

result exaple


No Training Game
1 10 10
2 30 60
___________________________
result 40 70


the code in footer works but i think its there false and it will be better in "where sql" without the doubled sql login

sorry form my bad english :?
admin 28
November 04 2008, 22:49 #16563
Hi qwarx,

maybe try this in the header :
<?php $totalresult = 0; ?>


in body :
<?php
$totalresult = $totalresult + $row->game;

?>


in footer:
<?php

echo $totalresult ;
?>


Max
Max
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!