calculations
Posted: Tue Nov 04, 2008 7:37 am
Hi, I am still learning MySQL and have been doing pretty well. I've run into a wall however and can't for the life of me figure out what I am doing wrong. If someone could point me in the right direction I would REALLY appreciate it.
I am attempting to populate a table with data. The table populates alright, but in the column for profit/loss/break even (where the result returned is supposed to have a color font appropriate to the status and a number unless even I always get "Broke even" no matter what data is fed into the equation. My equation is below;
global $profit_or_loss;
function calculate_differences($earnings,$cost)
{
$difference = $earnings - $cost;
if($difference = 0)
{
$difference = substr($difference,1);
$font_color ='green';
$profit_or_loss = "$".$difference."m";
}
elseif($difference >0)
{
$font_color ='blue';
$profit_or_loss = "$".$difference."m";
}
else
{
$font_color ='red';
$profit_or_loss = "$".$difference."m";
}
return "<font color='$font_color'>" . $profit_or_loss . "</font>";
}
...
I have a call to the function later on in the code as:
...
$movie_health = calculate_differences($movie_earnings, $movie_cost);
$page_start=<<<EOD
<HTML>
<head>
<title>Details and Reviews for: $movie_name</title>
</head>
<body>
EOD;
//global $profit_or_loss = $movie_health;
$movie_details =<<<EOD
<table width='70%' border='2' cellspacing='2' cellpadding='2' align='center'>
<tr>
<th colspan='6'><u><h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<tr>
<td width='33%' align='center'>$movie_name</td>
<td align='center'>$movie_year</td>
<td align='center'>$director</td>
<td align='center'>$leadactor</td>
<td align='center'>$movie_running_time</td>
<td align='center'>$movie_health</td>
</tr>
</table>
I have tried everything I can possibly think of, even starting over from scratch. Thanks a lot in advance!! I hope this is the correct forum, I posted it at a mysql forum and was asked why I had posted it there.
I am attempting to populate a table with data. The table populates alright, but in the column for profit/loss/break even (where the result returned is supposed to have a color font appropriate to the status and a number unless even I always get "Broke even" no matter what data is fed into the equation. My equation is below;
global $profit_or_loss;
function calculate_differences($earnings,$cost)
{
$difference = $earnings - $cost;
if($difference = 0)
{
$difference = substr($difference,1);
$font_color ='green';
$profit_or_loss = "$".$difference."m";
}
elseif($difference >0)
{
$font_color ='blue';
$profit_or_loss = "$".$difference."m";
}
else
{
$font_color ='red';
$profit_or_loss = "$".$difference."m";
}
return "<font color='$font_color'>" . $profit_or_loss . "</font>";
}
...
I have a call to the function later on in the code as:
...
$movie_health = calculate_differences($movie_earnings, $movie_cost);
$page_start=<<<EOD
<HTML>
<head>
<title>Details and Reviews for: $movie_name</title>
</head>
<body>
EOD;
//global $profit_or_loss = $movie_health;
$movie_details =<<<EOD
<table width='70%' border='2' cellspacing='2' cellpadding='2' align='center'>
<tr>
<th colspan='6'><u><h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<tr>
<td width='33%' align='center'>$movie_name</td>
<td align='center'>$movie_year</td>
<td align='center'>$director</td>
<td align='center'>$leadactor</td>
<td align='center'>$movie_running_time</td>
<td align='center'>$movie_health</td>
</tr>
</table>
I have tried everything I can possibly think of, even starting over from scratch. Thanks a lot in advance!! I hope this is the correct forum, I posted it at a mysql forum and was asked why I had posted it there.