p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 (http://p2p.wrox.com/forumdisplay.php?f=160)
-   -   Chapter 4 movie_details.php help (http://p2p.wrox.com/showthread.php?t=72913)

ilovesloth February 24th, 2009 09:44 AM

Chapter 4 movie_details.php help
I'm new to mysql but haven't found any problems following this book (apart from my typing [:D]) until the end of chapter 4.
I've added the extra bits from page 131 ("Displaying The Reviews") but when I open it up I get these 4 errors:

Notice: Undefined variable: review_result in C:\wamp\www\1 Craig\movie_details.php on line 100

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\1 Craig\movie_details.php on line 100

Notice: Undefined variable: review in C:\wamp\www\1 Craig\movie_details.php on line 128

Notice: Undefined variable: review_flag in C:\wamp\www\1 Craig\movie_details.php on line 177

They all seem to relate to "review_result" details I added but I can't find any spelling issues or anything. I've even gone back to to my last working backup and re-typed everything and tried downloading the code from here.

I'm not sure if it's related but when I used phpmyadmin to look at the database to check the reviews had been inserted ok it wouldn't let me look at the reviews table. I got the message saying I needed to re-enter my password as it had been inactive for over 1800 seconds yet I'd just logged in and the other 3 tables were accesable. This problem stopped when I rebooted my computer but i still get the 4 errors above.

Any help or suggestions would be greatly appreciated.
Here's the code as it is now:
$link = mysql_connect("localhost","bp5am","bp5ampass")
or die(mysql_error());

or die(mysql_error());

//function to calculate if a movie made a profit, loss or broke even
function calculate_differences($takings, $cost) {
$difference = $takings - $cost;

if ($difference < 0) {
$difference = substr($difference, 1);
$font_color = 'red';
$profit_or_loss = "$" . $difference . "m";

} elseif ($difference > 0) {
$font_color = 'green';
$profit_or_loss = "$" . $difference . "m";

} else {
$font_color = 'blue';
$profit_or_loss = "Broke even";

return "<font color=\"$font_color\">" . $profit_or_loss . "</font>";

//function to add image to ratings?
function generate_ratings($review_rating) {
$movie_rating = '';
for($i=0; $i<$review_rating; $i++) {
$movie_rating .= "<img src=\"carling2.gif\">&nbsp;";
return $movie_rating;

//function to get the directors name from the people table
function get_director() {
global $movie_director;
global $director;

$query_d = "SELECT people_fullname " .
"FROM people " .
"WHERE people_id='$movie_director'";

$results_d = mysql_query($query_d)
or die(mysql_error());

$row_d = mysql_fetch_array($results_d);
$director = $people_fullname;

//function to get the lead actors name from the people table
function get_leadactor() {
global $movie_leadactor;
global $leadactor;

$query_a = "SELECT people_fullname " .
"FROM people " .
"WHERE people_id='$movie_leadactor'";
$results_a = mysql_query($query_a)
or die(mysql_error());
$row_a = mysql_fetch_array($results_a);
$leadactor = $people_fullname;


$movie_query = "SELECT * FROM movie " .
"WHERE movie_id ='" . $_GET['movie_id'] . "'";

$movie_result = mysql_query($movie_query, $link)
or die(mysql());

<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>
<th>Date of Review</th>
<th>Review Title</th>
<th>Reviewer Name</th>
<th>Movie Review Comments</th>
while($review_row = mysql_fetch_array($review_result)) {
$review_flag =1;
$review_title[] = $review_row['review_name'];
$reviewer_name[] = ucwords($review_row['review_reviewer_name']);
$review[] = $review_row['review_comment'];
$review_date[] = $review_row['review_date'];
$review_rating[] = generate_ratings($review_row['review_rating']);
while ($row = mysql_fetch_array($movie_result)) {
$movie_name = $row['movie_name'];
$movie_director = $row['movie_director'];
$movie_leadactor = $row['movie_leadactor'];
$movie_year = $row['movie_year'];
$movie_running_time = $row['movie_running_time']." mins";
$movie_takings = $row['movie_takings'];
$movie_cost = $row['movie_cost'];

//get directors name from people table

//get lead actors name from people table


$i = 0;
$review_details = '';
while ($i<sizeof($review)) {
$review_details .=<<<EOD
<td width="15%" valign="top" align="center">$review-date[$i]</td>
<td width="15%" valign="top">$review_title[$i]</td>
<td width="10%" valign="top">$reviewer_name[$i]</td>
<td width="50%" valign="top">$review[$i]</td>
<td width="10%" valign="top" align="center">$review_rating[$i]</td>

$review_query = "SELECT * FROM reviews " .
"WHERE review_movie_id ='" . $_GET['movie_id'] . "' " .
"ORDER BY review_date DESC";

$review_result = mysql_query($review_query, $link)
or die(mysql());

$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =<<<EOD
<title>Details and Reeeviews for: $movie_name</title>
$movie_details =<<<EOD
<table width="70%" border="0" cellspacing="2" cellpadding="2" align="center">
<th colspan="6"><u><h2>$movie_name: Details</h2></u></th>
<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>
<br />
<br />
if ($review_flag) {
$movie_details .=<<<EOD
<table width="95%" border="0" cellspacing="2" cellpadding="20" align="center">
$page_end =<<<EOD
$detailed_movie_info =<<<EOD
echo $detailed_movie_info;

Cheerski [:)]

sandeepgreaternoida April 12th, 2009 04:32 PM

have u gone through chapter 3 successfully?

All times are GMT -4. The time now is 10:00 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.