Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 December 10th, 2004, 12:19 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 download file

I have been working for two days now trying to figure out how to make this work. This is the file from the download:(I have of course changed the information for my remote mysql and it works fine)All I get is Query was empty, I have also checked and made sure the fields in mysql are populated.

<?php
$link = mysql_connect("localhost","root","mysqlpass")
 or die(mysql_error());
     mysql_select_db("wiley") 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 "".$profit_or_loss."";
}

/* 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 generate_ratings($review_rating)
{
     for($i=0;$i<$review_rating;$i++)
     {
          $movie_rating .= "<img src='thumbsup.gif'> ";
     }
     return $movie_rating;
}

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

$movie_result = mysql_query($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($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 director's name from people table
     get_director($movie_director);

     //get lead actor's name from people table
     get_leadactor($movie_leadactor);

}

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

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

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

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

 
Old January 31st, 2005, 07:18 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi robtho,

I also had the exact same result when I downloaded the code from this site. The book is a bit vague as to where the modifications to your movie_details.php code should be made and it's important to have the correct code in the correct place for this exercise.

Fortunately, I've found an answer here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=24068

It seems that there are some pretty smart cookies using this p2p forum and the answer to your problem (and likely the cause) can be found at that link.

Best of luck!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Source download - chapter 5? dgy BOOK: Expert Access 2007 Programming ISBN 978-0-470-17402-9 1 January 8th, 2008 10:30 PM
Chapter 7 download file missing , C# version Judy BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 September 11th, 2007 09:06 AM
Smaller download/single download file available jminatel BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 21st, 2005 11:10 AM





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