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 27th, 2004, 12:49 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default stuck on page 131

after adding the reviews to the movie_details.php, i got this error

"Fatal error: Maximum execution time of 30 seconds exceeded in C:\Apache2\test\movie_details.php on line 168"

after fiddling around with the code i think the error lies on this line:

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

although im not sure, here is the whole code, any help is apreciated. many thanx



 <?php
$link= mysql_connect("localhost", "root", "") or die ("hey loser, check your server connection.");

mysql_select_db ("wiley3") or die ("hey loser, check your server connection.");

//Functions to calculate is a movie made a proffit, loss or broke even
function calculate_differance($takings,$cost)
{
    $differance=$takings-$cost;
    if($differance<0)
        {
        $differance=substr($differance,1);
        $font_color='red';
        $profit_or_loss="$".$differance."m";
        }
    elseif($differance>0)
        {
        $font_color='green';
        $profit_or_loss="$".$differance."m";
        }
    else
        {
        $font_color='blue';
        $profit_or_loss="Broke even";
        }
    return "".$profit_or_loss."";
}

//funcrion to get the direcors 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 actors 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;
}

$movie_query="SELECT * FROM movie WHERE movie_id='".$_GET['movie_id']."'";
$movie_result=mysql_query($movie_query,$link) or die(mysql_error());

$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_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($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'];
    $movie_takings=$row['movie_takings'];
    $movie_cost=$row['movie_cost'];

    //get directors name from people table
    get_director($movie_director);
    //get lead actors name from people table
    get_leadactor($movie_leadactor);

}

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

$movie_health=calculate_differance($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 with='95%' border='0' cell spacing='2' cellpadding='20' allign='center'>
        $review_table_headings
        $review_details
        </table>
EOD;
}

$review_table_headings=<<<EOD
    <tr>
        <th>Date of the Review</th>
        <th>Review Title</th>
        <th>Review 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[]=$review_row['review_rating'];
}

$i=0;
while(i<sizeof($review))
{
    $review_details .=<<<EOD
    <tr>
        <td width='15%' valign='top' align='center'>$review_date</td>
        <td width='15%' valign='top' >$review_title</td>
        <td width='10%' valign='top' >$reviewer_name</td>
        <td width='50%' valign='top' >$review</td>
        <td width='10%' valign='top' >$review_rating</td>
    </tr>
EOD;
    $i++;
}

$page_end=<<<EOD
        </body>
</html>
EOD;
$detailed_movie_info=<<<EOD
    $page_start
    $movie_details
    $page_end
EOD;

echo $detailed_movie_info;
mysql_close()
?>

 
Old December 30th, 2004, 04:12 PM
Authorized User
 
Join Date: Dec 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alright, there were quite a few things wrong with your code, but the main reason you were timing out was because of a missing dollar sign. Please read through my notes below that I've inserted in the code and you'll see what I'm talking about.



<?php
$link= mysql_connect("localhost", "root", "") or die ("hey loser, check your server connection.");

mysql_select_db ("wiley3") or die ("hey loser, check your server connection.");

//Functions to calculate is a movie made a proffit, loss or broke even
function calculate_differance($takings,$cost)
{
    $differance=$takings-$cost;
    if($differance<0)
        {
        $differance=substr($differance,1);
        $font_color='red';
        $profit_or_loss="$".$differance."m";
        }
    elseif($differance>0)
        {
        $font_color='green';
        $profit_or_loss="$".$differance."m";
        }
    else
        {
        $font_color='blue';
        $profit_or_loss="Broke even";
        }
    return "".$profit_or_loss."";
}

//funcrion to get the direcors 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 actors 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;
}

$movie_query="SELECT * FROM movie WHERE movie_id='".$_GET['movie_id']."'";
$movie_result=mysql_query($movie_query,$link) or die(mysql_error());

$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_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($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'];
    $movie_takings=$row['movie_takings'];
    $movie_cost=$row['movie_cost'];

    //get directors name from people table
    get_director($movie_director);
    //get lead actors name from people table
    get_leadactor($movie_leadactor);

}

/* the variable inputed into the below function was $review_ratings(with an 's'). I changed it to
    $review_rating. Otherwise, the rating isn't displayed.
*/
function generate_ratings($review_rating)
{
    for($i=0;$i<$review_rating;$i++)
        {
        $movie_rating .="<img src='thumbsup.gif'>&nbsp;";
        }
    return $movie_rating;
}

$movie_health=calculate_differance($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;


/* the following section was in the wrong place. It needed to be moved later in the
    code so that $review_table_headings and $review_details actually hold something.
    As it stands now, $review_table_headings and $review_details have yet to be
    defined, thus being empty. But more importantly, $review_flag has yet to be
    defined, so the 'if' statement isn't even parsed and the variables are not
    concatenated to $movie_details.

if($review_flag)
{
    $movie_details .=<<<EOD
        <table with='95%' border='0' cell spacing='2' cellpadding='20' allign='center'>
        $review_table_headings
        $review_details
        </table>
EOD;
}
*/

$review_table_headings=<<<EOD
    <tr>
        <th>Date of the Review</th>
        <th>Review Title</th>
        <th>Review 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']);
    /* the above line WAS incorrect because it did not call the function generate_ratings
        Instead, the line read $review_rating[]=$review_row['review_rating'];
    */
}

$i=0;
/* the following line is incorrect because it's missing the dollar sign. This is what
    was giving you the timeout error, because at the end of the while loop, you are telling the
    script to perform, $i++. Well, without $i instantiated, it cannot add one to itself, thus
    timing out.
while(i<sizeof($review))
    so...I changed it to the following(notice the dollar sign):
*/
while($i<sizeof($review))
{
    /* Next...the following section was incorrect as well. As you had it written, the actual word 'array'
    is printed for each instance instead of the actual value in the array.

    $review_details .=<<<EOD
    <tr>
        <td width='15%' valign='top' align='center'>$review_date</td>
        <td width='15%' valign='top' >$review_title</td>
        <td width='10%' valign='top' >$reviewer_name</td>
        <td width='50%' valign='top' >$review</td>
        <td width='10%' valign='top' >$review_rating</td>
    </tr>
EOD;
    So...I added [$i] on each line. This then properly references the value
    at each array position.
    */

     $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' >$review_rating[$i]</td>
    </tr>
EOD;

    $i++;
}

/* As I already indicated earlier, the following section was in the wrong place,
    and I've moved it to this location
*/
if($review_flag)
{
    $movie_details .=<<<EOD
        <table with='95%' border='0' cell spacing='2' cellpadding='20' allign='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 6th, 2005, 02:17 PM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank your very much for helping now i can get on with my learning, i also baught profeshional php to improve my knoledge of php.

thanks again. much appreciated.

 
Old December 1st, 2005, 12:40 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried what bodenzord suggested to a certain point and found that the main problem was reordering a bit of code. Specifically, the following lines:

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

needed to come before the use of the $review_result variable:

while($review_row = mysql_fetch_array($review_result))

Otherwise, there is no such variable for the while statement to refer to, thus producing an error such as:

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WebDesign\WebPractice\PHP\movie_details.php on line 108"

I hope that clears up exactly what went wrong for some people. Good luck, all!






Similar Threads
Thread Thread Starter Forum Replies Last Post
For Author - p 131 uberfist BOOK: Beginning VB.NET Databases 2 June 30th, 2005 12:52 PM
Stuck At Page 140 Yap Dreamweaver (all versions) 2 October 12th, 2004 06:49 PM
page stuck.... what's wrong? kaz VS.NET 2002/2003 7 December 13th, 2003 11:53 PM





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