Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| 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 April 4th, 2007, 07:49 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fatal Error - A tough one!

Hello Members,

I am on the last excercise in chapter 4. I am expecting to see a figure 4.7 on page 133. I edited the movie_details.php
and get the "fatal error". This is the error:

****ERROR******
Fatal error: Call to undefined function myqsl_fetch_array() in C:\Program_Files\wamp\www\trainning\chapter4\popul atingthetable\movie_details.php on line 114


I cannaot understand what is wrong with the code. Any help is greatly appriciated. Here is my code:


<?php
$link = mysql_connect("localhost","root","12345")
    or die(mysql_error());

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


//Function to calculate if a movie made 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 directors name

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 lead actors name

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


//Generate Ratings function

function generate_ratings($review_ratings) {
    $movie_ratings = '';
    for($i=0; $i<$review_rating; $i++) {
    $movie_rating .= "<img scr=\"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 Dirctor</th>
        <th>Movie Load Actor</th>
        <th>Movie Running Time</th>
        <th>Movie Health</th>
    </tr>
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;
}


$review_table_headings=<<<EOD
<tr>
    <th> Date of Review </th>
    <th> Review Title </th>
    <th> Reviewer Name </th>
    <th> Movie Review Comments </th>
    <th> Ratings </th>
</tr>
EOD;

while($review_row = myqsl_fetch_array($review_result)) {
    $review_flag =1;
    $review_title[] = $review_row['review_name'];
    $review_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 director's name from people table
get_director();

//get lead actor's name from peole 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> Detais 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();








Reply With Quote
  #2 (permalink)  
Old April 4th, 2007, 09:52 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here try this code out....

<?php
$link = mysql_connect("localhost","root","12345")
    or die(mysql_error());

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


//Function to calculate if a movie made 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 directors name

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 lead actors name

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

$movie_table_headings=<<<EOD
    <tr>
        <th>Movie Title</th>
        <th>Year of Release</th>
        <th>Movie Dirctor</th>
        <th>Movie Load Actor</th>
        <th>Movie Running Time</th>
        <th>Movie Health</th>
    </tr>
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;
}


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

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

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

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

?>


***** what happened was that you were getting that error on line 114 because you had a syntax error... it should have been mysql_fetch_array you had something like msyql_fetch_array... it was just misspelled thats all... The next error was chunks of code. They were placed in the wrong areas. I had this same problem too as i followed the books gray areas that said replace code with this put code here and their... or at times the book wasn't very detailed. I hope this makes sense i'm tired and the sun is up so I need to go to bed. But I will take a look at your code more later when i get a chance and all if you have any more questions... take care! Keep coding.

Reply With Quote
  #3 (permalink)  
Old April 4th, 2007, 12:54 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You make it look so easy!! :)

The only bad thing about this book is that future "try it out" examples are dependant on the current/previous ones. So no rooms for error.

Seems like a all-nighter for you...yes I seen many of those. Thank you once again and have a good sleep. :)
If you are ever in canada let me know!!

Gargamel

Reply With Quote
  #4 (permalink)  
Old April 4th, 2007, 04:25 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gargamel
 You make it look so easy!! :)

The only bad thing about this book is that future "try it out" examples are dependant on the current/previous ones. So no rooms for error.

Seems like a all-nighter for you...yes I seen many of those. Thank you once again and have a good sleep. :)
If you are ever in canada let me know!!

Gargamel

Thanks! No no nothing is always easy.... I'm usually up late because thats the only time I can do this because of college. Usually in the courses programming is taught like any other class which is pretty much trying to guess what the professor is going to have on the test to pass the class. So at the end no one ever really learns anything. So thats why I try to do this at night... But yeah if i'm in Canada I will say whats up...hahah Take care.. Just keep coding practice practice and take it easy.

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
FATAL ERROR. Help me please??? steviej1 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 11 February 27th, 2007 08:05 AM
Fatal Error?? dparsons ASP.NET 1.0 and 1.1 Professional 0 December 18th, 2006 01:55 PM
Fatal error: Cannot use [] for reading Targa BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 December 31st, 2005 07:42 AM
fatal error!!!! Ashleek007 Beginning PHP 6 October 9th, 2004 10:25 AM
Fatal error: singhzubin BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 April 11th, 2004 04:14 AM



All times are GMT -4. The time now is 08:19 PM.


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