0
<?php
$allsql="SELECT SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit) FROM billing,service,software,airtel";
    $profitall=mysql_query($allsql) or die(mysql_error());
while($row=@mysql_fetch_array($profitall))
            {
echo $row['SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit)'];
            }
            mysql_close($con);

?>

Hi everybody....

i have problem in mysql query..

i got the sum for the field called profit from each table...

i am getting the TOTAL value as wrong calculation value...

how do i get the total value from all the table...

Can anyone help me .. i have attached the code to get the total from all the table...

can anyone help me...

Edited by Dani: Formatting fixed

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by digital-ether
0

very bad code... you should save all the numbers in $vars and then plus them but with PHP, not with MySQL...

and put your code between [CODE.][/.CODE] TAGS...

<?php
$allsql="SELECT SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit) FROM billing,service,software,airtel";
$profitall=mysql_query($allsql) or die(mysql_error());
while($row=@mysql_fetch_array($profitall))
{
echo $row['SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit)'];
}
mysql_close($con);

?>

Edited by P0lT10n: n/a

0
<?php
					$allsql="SELECT SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit) FROM billing,service,software,airtel";
					$profitall=mysql_query($allsql) or die(mysql_error());
					while($row=@mysql_fetch_array($profitall))
					{
					echo $row['SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit)'];
					}
					mysql_close($con);
					?>
0

very bad code... you should save all the numbers in $vars and then plus them but with PHP, not with MySQL...

and put your code between [CODE.][/.CODE] TAGS...

<?php
$allsql="SELECT SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit) FROM billing,service,software,airtel";
$profitall=mysql_query($allsql) or die(mysql_error());
while($row=@mysql_fetch_array($profitall))
{
echo $row['SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit)'];
}
mysql_close($con);

?>

ya i have attached code between the code tags...

kindly help me ...

0

very bad code... you should save all the numbers in $vars and then plus them but with PHP, not with MySQL...

and put your code between [CODE.][/.CODE] TAGS...

<?php
$allsql="SELECT SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit) FROM billing,service,software,airtel";
$profitall=mysql_query($allsql) or die(mysql_error());
while($row=@mysql_fetch_array($profitall))
{
echo $row['SUM(Salesprofit)+SUM(Serviceprofit)+SUM(softwareprofit)+SUM(Airtelprofit)'];
}
mysql_close($con);

?>

how can i declare variables in php but i want to echo it in a page...

0

you cant declare variables, you can DEFINE variables, for example, if i use a lot of time an user, you should do:

define(USER,$user);
echo "Hello ".USER;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.