Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:11:07+00:00 2026-06-13T21:11:07+00:00

Here is a simple function which i made on PHP. The problem is that

  • 0

Here is a simple function which i made on PHP. The problem is that it is giving totally unexepected output.

From my database it takes $takings = 242 and $cost = 81 so it should show 242-81=161 as answer. but instead it is showing 242. What can be the problem ?

function differences($takings,$cost)
{
$difference = $takings - $cost;

if($difference < 0)
{
    $color = red;
    $difference = '$'.$difference.'million';
}

elseif($difference > 0)
{
   $color = green;
   $difference = '$'.$difference.='million';
}   

elseif($difference = 0)
{
   $color = blue;
   $difference = "broken even ";
}

return '<span style="color:'.$color.';">'.$difference.'</span>';
}

Guys. here is the complete code for the page. When open the page in the browser it shows this : enter image description here

<?php

function getdirector($director)
{
global $db;
$query = 'select name from peopledb where peopleid = '.$director;
$result = mysql_query($query) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $name;
}

function getactor($actor)
{
$query = 'select name from peopledb where peopleid = '.$actor;
$result = mysql_query($query) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $name;
}


function getmovietype($type)
{
$query = 'select movietype from movietype where movieid = '.$type;
$result = mysql_query($query) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $movietype;
}


function differences($takings,$cost)
{
$difference = $takings - $cost;

if($difference < 0)
{
    $color = red;
    $difference = '$'.$difference.'million';
}

elseif($difference > 0)
{
   $color = green;
   $difference = '$'.$difference.='million';
}   

elseif($difference = 0)
{
   $color = blue;
   $difference = "broken even ";
}

return '<span style="color:'.$color.';">'.$difference.'</span>';
}


$abc = $_GET['movieid'];


$db = mysql_connect('localhost','root','saw123') or die('Connection error');
mysql_select_db("moviesite",$db) or die(mysyql_error($db));
$query = "select moviename,releaseyear,director,actor,type,movierunningtime,moviecost,movietakings from movie where movieid = ". $abc;




$result = mysql_query($query,$db) or die(mysql_error($db));

$row = mysql_fetch_assoc($result);
$movie_name = $row['moviename'];
$movie_director = getdirector($row['director']);
$movie_releaseyear = $row['releaseyear'];
$movie_actor = getactor($row['actor']);
$movie_type = getmovietype($row['type']);
$movie_runningtime = $row['movierunningtime'].' minutes';
$movie_cost =$row['moviecost'].'million';
$movie_takings = $row['movietakings'].'million';
$movie_health = differences($row['movietakings'],$row['movie_cost']);



echo <<<ENDHTML
<html>
 <head>
   <title> Details and Reviews for the movies for $movie_name </title>
  </head>
<body>
<div style="text-align: center;">
<h2>$movie_name</h2>
<h3> details </h3>
<table cellpadding = "1" cellspacing = "4"
style = "width = 80% ;margin-left: auto;margin-right: auto;";>
<tr>
 <td><strong>Title</strong></strong></td>
 <td>$movie_name</td>
</tr>

<tr>
 <td><strong>release date</strong></strong></td>
 <td>$movie_releaseyear</td>
</tr>
<tr>

<tr>
 <td><strong>movie director</strong></strong></td>
 <td>$movie_director</td>
</tr>
<tr>

<tr>
 <td><strong>Lead Actor</strong></strong></td>
 <td>$movie_actor</td>
</tr>
<tr>

<tr>
 <td><strong>Running time</strong></strong></td>
 <td>$movie_runningtime</td>
</tr>
<tr>


<tr>
 <td><strong>Cost</strong></strong></td>
 <td>$movie_cost</td>
</tr>
<tr>


<tr>
 <td><strong>Takings</strong></strong></td>
 <td>$movie_takings</td>
</tr>
<tr>

<tr>
 <td><strong>Health</strong></strong></td>
 <td>$movie_health</td>
</tr>
<tr>


</table>
</div>

</body>
</html>
ENDHTML;



$table = <<<ENDHTML
<div style="text-align: center;">
<h2>The Ultimate movie database</h2>
<table border='1' cellpadding='1' cellspacing='2'
       style="width: 70%; margin-left: auto; margin-right: auto;">

<tr>
<th>Movie ID </th>
<th>Movie title</th>
<th>year of release </th>
<th>Movie director</th>
<th>Movie Actor</th>
<th>Movie type</th>
</tr>
ENDHTML;

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:11:09+00:00Added an answer on June 13, 2026 at 9:11 pm

    $movie_health = differences($row['movietakings'],$row['movie_cost']);

    should be

    $movie_health = differences($row['movietakings'],$row['moviecost']);

    Notice the last variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple function that converts a string to an integer. int str2int(char
I have made an encryption function which encrypts a simple value and stores it
I've made a simple JS which retrives data from my servlet. Data which I'm
I made some CMS in PHP which manipulates with data from MySQL. In my
I made a simple following-follower system with php(pdo) and mysql. My problem is, Let's
Here's a simple function to compute Fibonacci numbers: fib :: [Int] fib = 1
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have a simple Jquery function here: function submit_selection(del,submit) { del='yes'; submit=true; var ITAMZ=new
my sample code is here include 'simple_html_dom.php'; function get_all_links($url){ global $host; $html = new
jQuery-newbie here. I want to do a simple horizontal scroll function with two buttons.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.