これが私がPHPで作った簡単な関数です。問題は、まったく予期しない出力を提供していることです。
私のデータベースからは$takes=242と$cost= 81がかかるので、答えとして242-81=161と表示されるはずです。しかし、代わりに242を示しています。何が問題になる可能性がありますか?
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>';
}
彼ら。これがページの完全なコードです。ブラウザでページを開くと、次のように表示されます。
<?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;
?>