Jump to content

Finding the sum of a column


nextman

Recommended Posts

just to add to that, i have this code:

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
mysql_select_db($dbname);

$query = ("SELECT SUM(site_views) FROM pm_videos");
$result = mysql_query($query);

echo "$result";
?>

 

but all i get back is "Resource id #2"

UPDATE: got it working. heres the code i used, its pretty simple - sums up a column and displays it:

 

<?php
$sqla= "SELECT SUM(column_name) AS Total FROM table_name"; 

$result = mysql_query($sqla) 
or die (mysql_error()); 
while ($myrow = mysql_fetch_array($result)) 
{ 

$total=$myrow["Total"];


echo 'The total is '.$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.