1st is the one you did up for me.
<?php
// Connect to the database and select a database to use
$link = mysql_connect('localhost', 'root') or die(mysql_error());
mysql_select_db('moviedb1') or die(mysql_error());
/**
* Calculates difference between two amounts
*
* @param integer $earnings The amount brought in
* @param integer $cost The amount spent
*
* @return string XHTML string denoting difference between the amounts
*/
function calculate_differences($earnings, $cost)
{
$diff = $earnings-$cost;
$net = '$'.$diff.'m'; // $net is $6m now...
$color = '#000'; // Black for "even"
if($diff > 0)
$color = '#090';
elseif($diff < 0)
$color = '#900';
return '<span style="color:'.$color.';">'.$net.'</span>';
}
/*
Run a query on the movie table joining the people table so we don't have to go
back and get the names of the director and leadactor later. Gave every column
an alias so it's easier to deal with later. Limit the results to only 1 row
(since we're looking for a specific movie).
*/
$query = "SELECT movie_name AS name, movie_year AS year,movie_running_time AS length,
movie_earnings AS income, movie_cost AS expenses,
people_fullname AS director, people_fullname AS leadactor
FROM `movie`
INNER JOIN `people_isdirector`
ON people_isdirector = people_id
INNER JOIN `people_isactor`
ON people_isactor = people_id
WHERE movie_id=".intval($_GET['movie_id'])." /////////////////////////////////////////////////////////
LIMIT 1";
// Execute the query and put the returned data into an associative array: $movie
$result = mysql_query($query) or die(mysql_error());
$movie = mysql_fetch_assoc($result);
//
// Now, display the page:
?>
<html>
<head>
<title>Details and Reviews for: <?php echo $movie['name']; ?></title>
</head>
<body>
<table width='70%' border='2' cellspacing='2' cellpadding='2' align='center'>
<tr>
<th colspan='6'>
<h2 style="text-decoration:underline;"><?php echo $movie['name']; ?>: Details</h2>
</th>
</tr>
<tr>
<th> Movie Title</th>
<th> Year of Release</th>
<th> Movie Director</th>
<th> Movie Lead Actor</th>
<th> Movie Running Time</th>
<th> Movie Health</th>
</tr>
<tr>
<td width='33%' align='center'><?php echo $movie['name']; ?></td>
<td align='center'><?php echo $movie['year']; ?></td>
<td align='center'><?php echo $movie['director']; ?></td>
<td align='center'><?php echo $movie['leadactor']; ?></td>
<td align='center'><?php echo $movie['length']; ?></td>
<td align='center'><?php echo calculate_differences($movie['income'], $movie['expenses']); ?></td>
</tr>
</table>
</body>
</html>
Here is where the data is:
<?php
//Connect to mysql
$connect = mysql_connect ("localhost", "root")
or die ("Check the connection again");
//Make sure using correct database
mysql_select_db("moviedb1");
// insert data into table
$insert = "INSERT INTO movie (movie_id, movie_name, movie_type, " .
"movie_year, movie_leadactor, movie_director) " .
" VALUES (NULL, 'Lethal Weapon', 7, 1987, 1, 2), " .
"(NULL, 'Die Hard', 7, 1988, 3, 4), " .
"(NULL, 'Days of Thunder', 7, 1990, 5, 6), " .
"(NULL, 'Titanic', 2, 1997, 7, 8), " .
"(NULL, 'Real Genius', 5, 1985, 9, 10), " .
"(NULL, 'Meatballs', 5, 1979, 11, 12), " .
"(NULL, 'Nightmare on Elm Street', 6, 1984, 13, 14), " .
"(NULL, 'Smokey and the Bandit', 3, 1977, 15, 16), " .
"(NULL, 'The Others', 2, 2001, 17, 18), " .
"(NULL, 'Twister', 7, 1996, 19, 20)";
$results = mysql_query($insert)
or die(mysql_error());
// insert data into movie type table
$type = "INSERT INTO movietype (movietype_id, movietype_label) " .
"VALUES (NULL, 'Sci Fi'), " .
"(NULL, 'Drama'), " .
"(NULL, 'Adventure'), " .
"(NULL, 'War'), " .
"(NULL, 'Comedy'), " .
"(NULL, 'Horror'), " .
"(NULL, 'Action'), " .
"(NULL, 'Kids')" ;
$results = mysql_query($type)
or die(mysql_error());
//Insert data into people table
$people = "INSERT INTO people (people_id, people_fullname, " .
"people_isactor, people_isdirector) " .
"VALUES (NULL, 'Mel Gibson', 1, 0), " .
"(NULL, 'Richard Donner', 0, 1), " .
"(NULL, 'Bruce Willis', 1, 0), " .
"(NULL, 'Len Wisemen', 0, 1), " .
"(NULL, 'Tom Cruise', 1, 0), " .
"(NULL, 'Tony Scott', 0, 1), " .
"(NULL, 'Leonardo Decaprio', 1, 0), " .
"(NULL, 'James Cameron', 0, 1), " .
"(NULL, 'Val Kilmer', 1, 0), " .
"(NULL, 'Martha Coolidge', 0, 1), " .
"(NULL, 'John Baushi', 1, 0), " .
"(NULL, 'Ivan Reitman', 0, 1), " .
"(NULL, 'Robert Englund', 1, 0), " .
"(NULL, 'Wes Craven', 0, 1), " .
"(NULL, 'Burt Reynolds', 1, 0), " .
"(NULL, 'Hal Needham', 0, 1), " .
"(NULL, 'Nichole Kidman', 1, 0), " .
"(NULL, 'Alejandro Amenábar', 0, 1), " .
"(NULL, 'Bill Paxton', 1, 0), " .
"(NULL, 'Jan De Bont', 0, 1)";
$results = mysql_query($people)
or die(sql_error());
echo "Data inserted successfully!";
?>
And here is where the table is modified to include the other fields.
<?php
$link = mysql_connect("localhost", "root")
or die(mysql_error());
mysql_select_db("moviedb1")
or die(mysql_error());
//alter "movie" table to include running time/cost/takings fields
$add = "ALTER TABLE movie ADD COLUMN (
movie_running_time int NULL,
movie_cost int NULL,
movie_earnings int NULL)";
$results = mysql_query($add)
or die(mysql_error());
$update="UPDATE movie SET
movie_running_time=118,
movie_cost=280,
movie_earnings=137
WHERE movie_id = 1";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=102,
movie_cost=10,
movie_earnings=5
WHERE movie_id = 2";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=131,
movie_cost=60,
movie_earnings=157
WHERE movie_id = 3";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=194,
movie_cost=200,
movie_earnings=1848
WHERE movie_id = 4";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update = "UPDATE movie SET
movie_running_time=108,
movie_cost=1,
movie_earnings=12
WHERE movie_id = 5";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update = "UPDATE movie SET
movie_running_time=99,
movie_cost=1600,
movie_earnings=43046
WHERE movie_id = 6";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=91,
movie_cost=1800,
movie_earnings=25504
WHERE movie_id = 7";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=96,
movie_cost=1,
movie_earnings=126
WHERE movie_id = 8";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=104,
movie_cost=17,
movie_earnings=209
WHERE movie_id = 9";
$results = mysql_query($update)
or die(mysql_error());
//insert new data into "movie" table for each movie
$update="UPDATE movie SET
movie_running_time=113,
movie_cost=92,
movie_earnings=494
WHERE movie_id = 10";
$results = mysql_query($update)
or die(mysql_error());
?>