>> I have a column of amounts that was getting adding in a loop but I see
>> there's a sum() function to do this.  Should have known.   But I can't
>> make it work.  Can someone give me a simple query syntax using php?  


$table="my_table";
$field="some_field";
$sql="SELECT sum(cost) AS cost FROM '$table' GROUP BY '$field'";
$res=mysql_query($sql);
if (mysql_num_rows($res)>0) {
  while ($row=mysql_fetch_array($res)) {
    echo '<h1>'.$row["cost"].'</h1><br>';
  };
};


If no GROUP BY is used then it should return only one row.
Be sure your table is not empty!!!
Thats ALL!!!
Enjoy!



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to