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 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 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 Display Modes
  #1 (permalink)  
Old August 27th, 2012, 02:52 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error in displaying reviews.

IN THE BELOW MENTIONED EXAMPLE FROM CHAPTER 4: USING TABLES TO DISPLAY DATA I AM GETTING ERROR AS: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3. Below is the program and please help me out.

<?php

//function to generate ratings
function generate_ratings($rating) {
$movie_rating = '';
for ($i = 0; $i < $rating; $i++) {
$movie_rating .= '<img src="star.jpeg" alt="star"/>';
}
return $movie_rating;
}

//Function to take Id of a director and return his full name
function get_director($director_id) {
global $db;
$query = 'SELECT people_fullname
FROM people
WHERE people_id = ' . $director_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}

//Function to take Id of a lead_actor and return his full name
function get_leadactor($leadactor_id) {
global $db;
$query = 'SELECT people_fullname
FROM people
WHERE people_id = ' . $leadactor_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}

//Function to take id of a movie type and return type of movie.
function get_movietype($type_id) {
global $db;
$query = 'SELECT movietype_label
FROM movietype
WHERE movietype_id = ' .$type_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $movietype_label;
}

//This function will calculate whether the movie earned profit or went loss or even broke too.
function calculate_differences($takings, $cost) {
$difference = $takings - $cost;

if($difference < 0) {
$color = 'red';
$difference = '$'. abs($difference) . 'million';
} elseif ($difference > 0) {
$color = 'green';
$difference = '$'. $difference . 'million';
} else {
$color = 'blue';
$difference = 'broke even';
}

return '<span style="color:' . $color . ';">' . $difference . '</span>';
}
//connect to MySQL
$db = mysql_connect('localhost', 'satish', 'zoomin') or die('Unable to connect.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//retrieve information
$query = 'SELECT movie_name, movie_year, movie_director, movie_leadactor, movie_type, movie_running_time, movie_cost, movie_takings
FROM movie
WHERE movie_id = ' . $_GET['movie_id'];
$result = mysql_query($query, $db) or die(mysql_error($db));

$row = mysql_fetch_assoc($result);
$movie_name = $row['movie_name'];
$movie_director= get_director($row['movie_director']);
$movie_leadactor = get_leadactor($row['movie_leadactor']);
$movie_year = $row['movie_year'];
$movie_running_time = $row['movie_running_time'] . ' mins';
$movie_takings = $row['movie_takings']. 'million';
$movie_cost = $row['movie_cost'] . 'million';
$movie_health = calculate_differences($row['movie_takings'],$row['movie_cost']);

//display complete information.
echo <<<ENDHTML
<html>
<head>
<title> Details and Reviews for: $movie_name </title>
</head> <body>
<div style ="text-align: center;">
<h2>$movie_name</h2> <h3><em>DETAILS</em></h3>
<table cellpadding="2" cellspacing ="2"
style="width: 70%; margin-left: auto; margin-right: auto;">
<tr>
<td><strong>Title</strong></td> <td>$movie_name</td>
<td><strong>Release Year</strong></td> <td>$movie_year</td>
</tr>
<tr>
<td><strong>Movie Director</strong></td> <td>$movie_director</td>
<td><strong>Cost</strong></td> <td>$movie_cost</td>
</tr>
<tr>
<td><strong>Lead Actor</strong></td> <td>$movie_leadactor</td>
<td><strong>Takings</strong></td> <td>$movie_takings</td>
</tr>
<tr>
<td><strong>Running Time</strong></td> <td> $movie_running_time</td>
<td><strong>Health</strong></td> <td>$movie_health</td>
</tr>
</table>
ENDHTML;

//retrieve reviews for this movie
$query = 'SELECT
review_movie_id, review_date, reviewer_name, review_comment, review_rating
FROM
reviews
WHERE
review_movie_id = ' .$_GET['movie_id'] . '
ORDER BY
review_date DESC';
$result = mysql_query($query, $db) or die(mysql_error($db));

//display the reviews.
echo <<<ENDHTML
<h3><em> REVIEWS </em> </h3>
<table cellpadding="2" cellspacing="2"
style ="width: 90%; margin-left: auto; margin-right: auto;">
<tr>
<th style="width: 7em;"> Date </th>
<th style="width: 10em;"> Reviewer </th>
<th> Comments </th>
<th style="width: 5em;"> Rating </th>
</tr>
ENDHTML;

while ($row = mysql_fetch_assoc($result)) {
$date = $row['review_date'];
$name = $row['review_name'];
$comment = $row['review_comment'];
$rating = generate_ratings($row['review_rating']);

echo <<<ENDHTML
<tr>
<td style="vertical-align:top; text-align: center;">$date</td>
<td style="vertical-align:top;">$name</td>
<td style="vertical-align:top;">$comment</td>
<td style="vertical-align:top;">$rating</td>
</tr>
ENDHTML;
}
echo <<<ENDHTML
</div>
</body>
</html>
ENDHTML;
?>
Reply With Quote
Reply


Thread Tools
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
Chapter 4: Pages 130 - 132 Querying for reviews & Displaying the reviews FlaUsa BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 January 24th, 2012 12:55 AM
chapter 13 , Bullets Reviews not displaying anjumk BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 October 7th, 2011 12:03 PM
Chapter 4:Displaying the reviews p.126-128 drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 6 November 6th, 2010 04:04 AM
Authorized reviews sophia BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 11 October 6th, 2010 07:56 AM
Reviews jack_hilary BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 May 23rd, 2010 03:55 PM



All times are GMT -4. The time now is 08:59 AM.


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