Jump to content

sum column


proctk

Recommended Posts

Hi

Below is code that I'm trying to use to display all entrys found in a table and sum the values of a column
The problem is its not showing all the enterys when I click the letters the enterys show but it will not show all.


any help is great

[code=php:0]
<div id="twoColumnLeft">
<?php include '../leftlinks.php'; ?>

</div>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="EditRegion4" -->
<div id="twoColumnRight">
  <?php

include ('../config/db.php');

$username = $_SESSION['username'];


for ($x=65; $x<=90; ++$x):
        echo '        <a href="users.php?index=' .chr($x). '">' .chr($x). "</a>\n";
    endfor;
  echo '        <a href="users.php?index=*">ALL'."</a>\n";
echo '<br />';

$index = strtoupper(substr($_GET['index'],0,1));
if($index != '*' && (ord($index) < 65 || 90 < ord($index))) $index = '*';

//if $index is *, then we replace with %, otherwise, we concat % to the end of index.
$index = ($index == '*') ? '%' : $index.'%';

$query = ("Select users.last_name, users.first_name, users.username, users.user_level, users.signup_date, users.last_login, users.space, images.size, IFNULL(sum(images.size),0) as totalSize From `users`,images Where `last_name` Like '{$index}' group by images.owner_id = users.user_id");


$result=mysql_query($query)or die("Get Search results Error: ".mysql_error());

if(mysql_num_rows($result) >0) {


?>

<table class='columntable'>
<tr>
<th class='tableheader' colspan='8'>Registered Users</th><br>
</tr>

<td class='rowLeft'><b>Change</b></td>
<td class='rowLeft'><b>Last Name</b></td>
<td class='rowLeft'><b>First Name</b></td>
<td class='rowLeft'><b>User Name</b></td>
<td class='rowLeft'><b>User Level</b></td>
<td class='rowLeft'><b>Last Login</b></td>
<td class='rowLeft'><b>Disk Space</b></td>
<td class='rowRight'><b>Space Used</b></td>
</tr>

<?php while($r=mysql_fetch_assoc($result)) {

?>

  <tr>
<td class='rowLeft'><a href='manageUser.php?do=$id'>Edit</a></td>
  <td class='rowLeft'><?php echo $r['last_name']; ?></td>
  <td class='rowLeft'><?php echo $r['first_name']; ?></td>
  <td class='rowLeft'><?php echo $r['username']; ?></td>
  <td class='rowLeft'><?php echo $r['user_level']; ?></td>
  <td class='rowLeft' title="<?php echo 'Sign up date: '.$r['signup_date']; ?>"><?php echo $r['last_login']; ?></td>
  <td class='rowLeft'><?php echo $r['space']; ?></td>
  <td class='rowRight'><?php echo $row_image_owner['totalSize']; ?></td>
<?php  }?>
 
  </tr>

</table>
<?php  }?>
  </div>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/28929-sum-column/
Share on other sites

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.