Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 24th, 2009, 09:44 AM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter 4 movie_details.php help

Hi,
I'm new to mysql but haven't found any problems following this book (apart from my typing ) 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:
<?php
$link = mysql_connect("localhost","bp5am","bp5ampass")
or die(mysql_error());

mysql_select_db("moviesite")
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);
extract($row_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);
extract($row_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());

$movie_table_headings=<<<EOD
<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>
EOD;
$review_table_headings=<<<EOD
<tr>
<th>Date of Review</th>
<th>Review Title</th>
<th>Reviewer Name</th>
<th>Movie Review Comments</th>
<th>Rating</th>
</tr>
EOD;
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_director();

//get lead actors name from people table
get_leadactor();

}

$i = 0;
$review_details = '';
while ($i<sizeof($review)) {
$review_details .=<<<EOD
<tr>
<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>
</tr>
EOD;
$i++;
}

$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
<html>
<head>
<title>Details and Reeeviews for: $movie_name</title>
</head>
<body>
EOD;
$movie_details =<<<EOD
<table width="70%" border="0" 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>
<br />
<br />
EOD;
if ($review_flag) {
$movie_details .=<<<EOD
<table width="95%" border="0" cellspacing="2" cellpadding="20" align="center">
$review_table_headings
$review_details
</table>
EOD;
}
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
$page_start
$movie_details
$page_end
EOD;
echo $detailed_movie_info;
mysql_close();
?>

Cheerski
Reply With Quote
  #2 (permalink)  
Old April 12th, 2009, 05:32 PM
Authorized User
 
Join Date: Dec 2007
Location: greaternoida, u.p, India.
Posts: 66
Thanks: 9
Thanked 2 Times in 2 Posts
Send a message via AIM to sandeepgreaternoida Send a message via MSN to sandeepgreaternoida Send a message via Yahoo to sandeepgreaternoida Send a message via Skype™ to sandeepgreaternoida
Default

have u gone through chapter 3 successfully?
__________________
sandeep gupta

Last edited by sandeepgreaternoida; April 12th, 2009 at 05:33 PM. Reason: s
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
movie_details.php issues gargamel BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 12 October 24th, 2010 07:02 AM
chapter 10 Emailing with php - firstmail.php vijdev BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2007 02:12 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Chapter 4 P124 - movie_details Pheeal Beginning PHP 0 January 27th, 2006 10:16 AM
need help with movie_details.php code kjames1973 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 December 26th, 2004 04:28 PM



All times are GMT -4. The time now is 11:07 AM.


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