Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2012, 01:55 AM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter 4: Pages 130 - 132 Querying for reviews & Displaying the reviews

Hello;

I am current at the end of chapter four working on pages 130 - 132 in the Try it out sections titled 'Querying for the Reviews' and 'Displaying the Reviews' and I am having a problem. Followiing the directions given on these pages I modified my movie_details.php page accordingly but at the end when I load Table3.php into my browser, I can click on the link for each of the movies but when the movie details page comes up for each movie, all I get is the information for each movie showing it health and with the title underlined on the screen. However, I can't click on the underlined title to get the movie reviews to show for each page. I have typed this code in twice now and reviewed what I typed in at least 3 times and can not find any errors in my code that would be causing this to happen. Can someone take a look at my code below and tell me if and where I may have made an error and what I need to do to correct it so I can see the movie reviews? BTW, I was very careful not to leave any white space after the variables.

Thanks!

Chris

__________________________________________________ ______________

<?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 get the director's 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 actor's 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;
}

/* Function to generate ratings for movies */
function generate_ratings($review_rating) {
$movie_rating = '';
for($i=0; $i<review_rating; $i++) {
$movie_rating .= "<img src=\"thumbsup.gif\">&nbsp;";
}
return $movie_rating;
}

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

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

$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']);
}

$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++;
}

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 actor's name from people table
get_leadactor();

}

$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_error());

$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =<<<EOD
<html>
<head>
<title>Details and Reviews 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();

?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 13 , Bullets Reviews not displaying anjumk BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 October 7th, 2011 12:03 PM
Chapter 12 Management.reviews is not allowed bc it does not extend system.web.ui.page tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 August 5th, 2011 10:35 AM
Chapter 4:Displaying the reviews p.126-128 drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 6 November 6th, 2010 04:04 AM
Reviews jack_hilary BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 May 23rd, 2010 03:55 PM
problems with the reviews table in chapter 4 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 15th, 2007 03:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.