stormx Posted June 21, 2008 Share Posted June 21, 2008 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 ??? Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/ Share on other sites More sharing options...
maxudaskin Posted June 21, 2008 Share Posted June 21, 2008 $query = mysql_query("SELECT * FROM `table` WHERE `column` = 'value' ORDER BY `column` DESC"); $rows = mysql_num_rows($query) If the query brings up 3 results, then $rows will be set to 3. Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570789 Share on other sites More sharing options...
zenag Posted June 21, 2008 Share Posted June 21, 2008 select SUM (fieldname) as somename from table name Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570792 Share on other sites More sharing options...
stormx Posted June 21, 2008 Author Share Posted June 21, 2008 <?php $query = mysql_query("SELECT * FROM `logs` WHERE `username` = '$user1'"); $rows = mysql_num_rows($query) echo $rows['filesize']; ?> Is that correct? Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570794 Share on other sites More sharing options...
mmarif4u Posted June 21, 2008 Share Posted June 21, 2008 if i am wrong, correct me. Did u want to show a single users row to them,when they login or what ever. Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570797 Share on other sites More sharing options...
stormx Posted June 21, 2008 Author Share Posted June 21, 2008 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']; ?> Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570799 Share on other sites More sharing options...
mmarif4u Posted June 21, 2008 Share Posted June 21, 2008 Can you explain a bit your need from that code. That code will show rows to a specific user,who is login. Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570801 Share on other sites More sharing options...
stormx Posted June 21, 2008 Author Share Posted June 21, 2008 I need FileSize (KB) or filesize to be totaled up. Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570806 Share on other sites More sharing options...
stormx Posted June 21, 2008 Author Share Posted June 21, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570843 Share on other sites More sharing options...
zenag Posted June 21, 2008 Share Posted June 21, 2008 (eg) files1: 12KB file2: 13KB total :25KB do u need like this one????? Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570846 Share on other sites More sharing options...
sasa Posted June 21, 2008 Share Posted June 21, 2008 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; ?> Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570850 Share on other sites More sharing options...
zenag Posted June 21, 2008 Share Posted June 21, 2008 yeah it displays total file size...what probs in that??? Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570855 Share on other sites More sharing options...
stormx Posted June 21, 2008 Author Share Posted June 21, 2008 Thanks sasa and all you other guys.. you all have been a big help I guess I got a long road in front of me to learn more PHP :-\ BIG Thanks. Link to comment https://forums.phpfreaks.com/topic/111207-solved-how-to-total-up-stuff-in-a-database/#findComment-570886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.