PHP - how to calculate % and how to stop form from auto submit.

Asked By Olusegun A. on 12-Oct-09 08:59 AM
Hello Success-Oriented People,

I want to calculated 90% and a particular amount am having in my database. I named the column of the amount in the database [b]abalance[/b]. this is the code i tried but its not working,


What is the way out?

Secondly, am having a form where members can edit their account. When the member clicked on edit profile from his/her welcome page, the below page will be opened. my problem is that starting the form with teh IF function in order to stop the form from submitting automatically, whenever the page is loaded, the page will not echo out the members informations but if i removed the IF function, all the members information will be display but the form will be submitting itself automatically.


$check=mysql_query("select * from clients where id='$id'");
$update=mysql_query("update clients set fname='$nfname', mname='$nmname', lname='$nlname', address='$naddress', address2='$naddress2', city='$ncity', state='$nstate', country='$ncountry', pcode='$npcode', gender='$ngender', pno='$npno', pno2='$npno2', atype='$natype', currency='$ncurrency', status='$nstutas' where ano='$ano'");
echo "The Information is not updated, try again.<br>";
echo "The Information is updated successfully.<br>";
what can i do to this form?


reply - Deepak Sonawane replied to Olusegun A. on 12-Oct-09 09:12 AM


Here is function in php that you can use to calculate percentage:

function percent($num_amount) {
$count1 = 90*$num_amount ;
$count2 = $count1 / 100;
$count = number_format($count2, 0);
echo $count;

ffunction percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;
}unction percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;