Adding values retrieved from a db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Adding values retrieved from a db

Post by a94060 »

Hi,i would like to nkow how i can add the values recieved from a query. the query i use is

Code: Select all

$sql = "SELECT * FROM `coffers` WHERE `username`='" . $payee . "' AND `payed`='N'";
i want to add all the values from the values colums which i have already recieved like this:

Code: Select all

while ($array = mysql_fetch_array($result)) {
  echo '<br>';
    echo '<table width="200" border="1" cellspacing="7" cellpadding="7">';
    echo '<th>Offer Name</th>';
    echo '<th>Completed By</th>';
	echo '<th>Offer Value</th>';

    
    while($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
	echo '<tr>';
    echo '<td>' .$array['offer_name']. '</td>';
    echo '<td>' .$array['username']. '</td>';
	echo '<td>$' .$array['value']. '</td>';

}
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Code: Select all

$sumSQL = "SELECT SUM(*) FROM `coffers` WHERE `username`='" . $payee . "' AND `payed`='N'";
$total = mysql_result($sumSQL, 0);
Also why are you nesting 2 identical while loops... you're throwing away the first result in the set if you do it that way.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

whoops,im sorry. but thatnks for the help.
Post Reply