Forums

Sum of Table Row`s

qwarx 04 Nov, 2008
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
Max_admin 04 Nov, 2008
Hi Andy,

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

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
qwarx 04 Nov, 2008
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 :?
Max_admin 04 Nov, 2008
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
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.