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 Search this Thread Display Modes
  #1 (permalink)  
Old November 3rd, 2008, 05:18 PM
Registered User
 
Join Date: Oct 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 calculations

Hi, I am really hung up. I have the exact same code (even tried copy and paste from the web site just to see it work) and it still doesn't Whenever I click one of the movie links on the site I am making I get the table quite nicely, but under movie running time I have "mins" and under movie health I always get "broke even", no matter what the movie did....and I get no numbers. I verified the info in the table and made certain the code is correct, I come up dry. If someone could point me in the right direction I would REALLY appreciate it!

Here is my code:

<?php

  $link = mysql_connect("localhost", "root")
  or die(mysql_error());

  mysql_select_db("moviedb1")
  or die(mysql_error());


/* Function to calculate if a movie made a profit,
loss or broke even */
global $profit_or_loss;
function calculate_differences($earnings,$cost)

{
     $difference = $earnings - $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 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 get actors name from 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_earnings = $row['movie_earnings'];
     $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);

}


$movie_health = calculate_differences($movie_earnings, $movie_cost);
  $page_start=<<<EOD
  <HTML>
   <head>
        <title>Details and Reviews for: $movie_name</title>
   </head>
   <body>
EOD;
//global $profit_or_loss = $movie_health;
$movie_details =<<<EOD
<table width='70%' border='2' 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;

// <td align='center'>$movie_health</td>
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
$page_start
$movie_details
$page_end
EOD;

echo $detailed_movie_info;
mysql_close();




?>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Date Calculations edove ASP.NET 2.0 Basics 0 March 30th, 2007 07:05 AM
time calculations lizhaskin Access 1 November 10th, 2005 08:48 AM
Date Calculations Stu_morris40 Infopath 0 November 1st, 2005 11:53 AM
DateTime calculations sudarshan73 SQL Language 8 April 7th, 2005 09:07 AM
calculations between records plenarts Access 5 December 30th, 2004 08:05 AM



All times are GMT -4. The time now is 05:33 PM.


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