Jump to content

[SOLVED] How to total up stuff in a database?


stormx

Recommended Posts

Hey,

 

I have been doing a lot of research and just cannot find the answer, I got php to generate a table from MySQL stats, now it gets all the information from the database for the specific logged in user and will display it, under the table I want to put the totals of the numbers.

 

If you can't understand what I have just said, this is an example: http://img145.imageshack.us/img145/2386/tabletotalvs4.jpg

 

It basically needs to calculate the users rows if I have said it clearly or something on the lines of that, I guess I'm a newbie to this ???

This was my full code:

 

<?php

$user1 = $_SESSION['username'];

$user_sql = mysql_query("SELECT * FROM `users` WHERE `username` = '$user1'");

$userinfo = mysql_fetch_array($user_sql);

$username =  $userinfo['username'];



$sql1 = mysql_query("SELECT * FROM `logs` WHERE `username` = '$username'") or die("Cannot select History at this time");



$sql1_rows = mysql_num_rows($sql1);







if($sql1_rows == "0") {



echo 'You have never done anything.';



} else {



echo '<table border="0" align="center" width="60%">



<tr>




<th>Date</th>



    <th>File Name</th>



    <th>FileSize (KB)</th>



<th>IP</th>







</tr>';



while($history = mysql_fetch_array($sql1)) {



echo '<tr>



    <td align="center">'.$history['fdate'].'</th>



<td align="center">'.$history['filename'].'</th>



    <td align="center">'.$history['filesize'].'</th>

    <td align="center">'.$history['ip'].'</th>






</tr>';



}



echo '</table>';



}



?>
    </p>
    <p align="center">Total:</p>
    <p align="center">
        
       <?php

$query = mysql_query("SELECT * FROM `logs` WHERE `username` = '$user1'"); 
$rows  = mysql_num_rows($query)

echo $rows['filesize'];

?>

try

<?php
$user1 = $_SESSION['username'];
$user_sql = mysql_query("SELECT * FROM `users` WHERE `username` = '$user1'");
$userinfo = mysql_fetch_array($user_sql);
$username =  $userinfo['username'];
$sql1 = mysql_query("SELECT * FROM `logs` WHERE `username` = '$username'") or die("Cannot select History at this time");
$sql1_rows = mysql_num_rows($sql1);
if($sql1_rows == "0") {
echo 'You have never done anything.';
} else {
$total = 0;
echo '<table border="0" align="center" width="60%">
<tr>
  <th>Date</th>
    <th>File Name</th>
    <th>FileSize (KB)</th>
   <th>IP</th>
</tr>';
while($history = mysql_fetch_array($sql1)) {
$total += $history['filesize'];
echo '<tr>
    <td align="center">'.$history['fdate'].'</th>
   <td align="center">'.$history['filename'].'</th>
    <td align="center">'.$history['filesize'].'</th>
    <td align="center">'.$history['ip'].'</th>
</tr>';
}
echo '</table>';
}
?>
     </p>
     <p align="center">Total:</p>
     <p align="center">
<?php
//$query = mysql_query("SELECT * FROM `logs` WHERE `username` = '$user1'");
//$rows  = mysql_num_rows($query);
echo $total;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.