Wrox Programmer Forums
|
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 August 7th, 2006, 01:53 PM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 page 127

The code below get no errors but, does not pull data from the database. At first, I thought it just wasn't loading into the table. I tested it by adding echo statements to see if the query pulled any data. Nothing was displayed. I can't finish the chapter if I can't get this.

<?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 "" . $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;
}

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

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


while ($row = mysql_fetch_array($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();

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

}

$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;
$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 3 page 95 nead23 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 March 26th, 2009 09:28 AM
Tomcat +SEVERE: Remote Host /127.0.0.1 SocketExcep ItsNeverLateToStartAgain Apache Tomcat 1 September 4th, 2007 06:17 AM
Try It Out Page 146 Chapter 5 sosborne BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 August 7th, 2006 05:53 PM
Chapter 5 Example 1 p126 - 127 jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 June 15th, 2004 10:35 AM





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