One of the ways:
Use a temp variable , say $total with initial value =0 , then increment it by $res["price"]
then if the des changes (or is at the end of the foreach loop), displays this variable and reset it to 0
Sample Data
<?php
$resulta[] = array("des"=>"samsung led tv", "name"=>'', "slug"=>'', $details=>'', "price"=>"8.99");
$resulta[] = array("des"=>"samsung led tv", "name"=>'', "slug"=>'', $details=>'', "price"=>"41.99");
$resulta[] = array("des"=>"samsung led tv", "name"=>'', "slug"=>'', $details=>'', "price"=>"144.99");
$resulta[] = array("des"=>"macbook pro", "name"=>'', "slug"=>'', $details=>'', "price"=>"2499.99");
$resulta[] = array("des"=>"macbook pro", "name"=>'', "slug"=>'', $details=>'', "price"=>"649.99");
$resulta[] = array("des"=>"macbook pro", "name"=>'', "slug"=>'', $details=>'', "price"=>"148.99");
$resulta[] = array("des"=>"dell vostro 3557", "name"=>'', "slug"=>'', $details=>'', "price"=>"1499.99");
?>
PHP Code
<table border=1>
<?php
$initdesc="undefined"; $count=0; $total=0;
foreach ($resulta as $res) {
if ($initdesc !=$res["des"]) {
if ($count > 0) { ?>
<tr><td colspan=4 style="text-align:right;">Total<td><?php echo $total; ?>
<?php }
$total=0;
$initdesc=$res["des"];
}
?>
<tr>
<td><?php echo $res['des'] ?></td>
<td><?php echo $res['name'] ?></td>
<td><?php echo $res['slug'] ?></td>
<td><?php echo $res['details'] ?></td>
<td><?php echo $res['price'] ?></td>
</tr>
<?php
$count++;
$total=$total+$res['price'];
}
if ($count!=0) { ?>
<tr><td colspan=4 style="text-align:right;">Total<td><?php echo $total; ?>
<?php } ?>
</table>