Extending Cgrideview

<Am currently developing a school management system, in the school fees module I what to achieve the following objective

  1. Once the student pay fee, the accountant enter the amount in the amount collect text field

  2. The amount entered is assign to each raw by a loop that compared the amount of the item and the remaining amount is assign to the next item i.e $item Amount= school_fees_paid – item_amount

  3. If $item Amount=0 THEN the item raw is assign zero

  4. The whole grid view and the textfield on the form is submitted to the database

I have manage to do that in plain php like this.

<?php

$sum=0;

$ad=6; //i assumed this to be the amount entered by the accountanty

$a = array(1, 2, 3, 4, 5); //this are assumed to be the item that a student is supposed to pay

foreach ($a as $B)

{

?>

<?php

//echo $b."<br>";?><?php

$sum=$ad-$b; //minus the item amount from the school fees payed

//print "<br>".$b . " <br>";

if ($sum<=0){ //if the result if less or equal to zero the raw cell is automaticaly initialized by zero

echo (&#036;sum=0).&quot;&lt;br&gt;&quot;;











}


else{echo &#036;b.&quot;&lt;br&gt;&quot;;}

$ad=$sum; //the next loop is assign with the result of the curre

//echo $ad;

}

?>

This is displaying correctly but when I use the following function the raws do not display correctly

The function I use is:

<?php

Yii::import(‘zii.widgets.grid.CDataColumn’);

Class SumColumn Extends CDataColumn {

public &#036;name = 'amount';


public &#036;sum = 0;





public function getHasFooter() {


	return True;


}





public function renderDataCellContent(&#036;row, &#036;data) {


	&#036;fee=1000;


	&#036;amount = &#036;data-&gt;{&#036;this-&gt;name};


	


	//------------------minus the fee ammount from the amount assing-------------////////


	foreach(array(&#036;amount) as &#036;val){


		&#036;sum=&#036;fee-&#036;val;//minus the item amount from the school fees payed


		&#036;fee=&#036;sum; //the new fee amount


		


		}


	//echo &#036;sum;


	


	


	&#036;this-&gt;sum = &#036;this-&gt;sum +(float)&#036;amount;


	echo &#036;amount;


}





public function renderFooterCellContent() {


	echo (float)&#036;this-&gt;sum.'.'.'00';


}

}?>

figure 1

Problem

How can display accurate amount calculated on the amount column

How to save the data in the database>

always post your source codes using code button(<>) to read easier




<?php

$sum=0;

$ad=6; //i assumed this to be the amount entered by the accountanty

$a = array(1, 2, 3, 4, 5); //this are assumed to be the item that a student is supposed to pay


foreach ($a as $<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />


{

?>


<?php

//echo $b."<br>";?><?php

$sum=$ad-$b; //minus the item amount from the school fees payed

//print "<br>".$b . " <br>";


if ($sum<=0){ //if the result if less or equal to zero the raw cell is automaticaly initialized by zero

echo ($sum=0)."<br>";





}

else{echo $b."<br>";}

$ad=$sum; //the next loop is assign with the result of the curre

//echo $ad;

}


?>

This is displaying correctly but when I use the following function the raws do not display correctly

The function I use is:

<?php

Yii::import('zii.widgets.grid.CDataColumn');


Class SumColumn Extends CDataColumn {

public $name = 'amount';

public $sum = 0;


public function getHasFooter() {

return True;

}


public function renderDataCellContent($row, $data) {

$fee=1000;

$amount = $data->{$this->name};


//------------------minus the fee ammount from the amount assing-------------////////

foreach(array($amount) as $val){

$sum=$fee-$val;//minus the item amount from the school fees payed

$fee=$sum; //the new fee amount


}

//echo $sum;




$this->sum = $this->sum +(float)$amount;

echo $amount;

}


public function renderFooterCellContent() {

echo (float)$this->sum.'.'.'00';

}

}?>