Page 1 of 1

Adding values retrieved from a db

Posted: Tue Jun 20, 2006 5:44 pm
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>';

}

Posted: Tue Jun 20, 2006 5:58 pm
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.

Posted: Tue Jun 20, 2006 6:57 pm
by a94060
whoops,im sorry. but thatnks for the help.