<?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...

Member Avatar for P0lT10n

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);

?>
<?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);
					?>

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

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

Member Avatar for P0lT10n

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;

It would be a lot simpler to get the sums one by one and add it in PHP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.