Jump to content

Getting a sum total


figuringout

Recommended Posts

I get a result from a MySQL db, the result has some html tags and a pound sign in. I'd like to add all the results together and get a total, but I'm not sure exactly how I do it. The code here simply adds the last result to itself, I'd like a total of all the results.

$query2="SELECT text FROM orders_total where  orders_id = " . $orders_id .  " and text like '%<b>%'";
$result2=tep_db_query($query2);
while($nt=mysql_fetch_array($result2))
{
	$nt = str_replace("£", "", $nt);
	echo strip_tags("$nt[text]");

	$val1= strip_tags("$nt[text]");
	$sum=$val1 + $val1;
	}
print ' order object was created  ' . $orders_id .  '<br>' ;
		}
				}
echo $val1;

 

Link to comment
Share on other sites

You want to keep adding to $sum with: $sum += $val1, then display $sum at the end

 

<?php
$query2="SELECT text FROM orders_total where  orders_id = " . $orders_id .  " and text like '%<b>%'";
$result2=tep_db_query($query2);
while($nt=mysql_fetch_array($result2))
{
$nt = str_replace("£", "", $nt);
echo strip_tags("$nt[text]");
$val1= strip_tags("$nt[text]");
$sum += $val1;
}
print ' order object was created  ' . $orders_id .  '<br>' ;
}//Where are these coming from?
}//Where are these coming from?
echo $sum;
?>

Link to comment
Share on other sites

$query2="SELECT text FROM orders_total where  orders_id = " . $orders_id .  " and text like '%<b>%'";
$result2=tep_db_query($query2);
while($nt=mysql_fetch_array($result2))
{

	$nt = str_replace("£", "", $nt);
	echo strip_tags("$nt[text]");

	$val1= strip_tags("$nt[text]");
	if(!$su){$sum = array_sum($nt);$su=TRUE;}
	}
print ' order object was created  ' . $orders_id .  '<br>' ;
		}
				}
echo $val1;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.