Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Problem Displaying a table

Status
Not open for further replies.

mkohl

Programmer
Feb 22, 2005
82
US
Im learning PHP and have a problem displaying a table. I have a page that displays two tables one table is for movies, and the other is for movie reviews.

Problem: The Review Table will not display. Any help is appreciated.

here is the code:

<?php
$host="localhost";
$user="root";
$pass="password";

$link = mysql_connect($host,$user,$pass) or
die (mysql_error());

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

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 "<font color=\"$font_color\">" . $profit_or_loss . "</font>";
}

function get_director(){
global $movie_director;
global $director;

$query_d = "select people_fullname " .
"from people " .
"where people_id='$movie_director' ";
$result_d = mysql_query($query_d) or
die(mysql_error());
$row_d = mysql_fetch_array($result_d);
extract($row_d);
$director = $people_fullname;
}

function get_leadactor(){
global $movie_leadactor;
global $leadactor;

$query_a = "select people_fullname " .
"from people " .
"where people_id='$movie_leadactor'";
$result_a = mysql_query($query_a) or
die (mysql_error());
$row_a = mysql_fetch_array($result_a);
extract($row_a);
$leadactor = $people_fullname;
}

function generate_ratings($review_rating){
$movie_rating = '';
for($i= 0; $i<$review_rating; $i++){
$movie_rating .= "<image src=\"thubsup.jpeg\">$hbsp;";
}
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());

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

$review_table_headings=<<<EOD
<tr>
<th>date of reviews</th>
<th>review title</th>
<th>reviewer 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']);
}


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();
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>Details and Reviews for: $movie_name</title>
</head>
<body>
EOD;

$movie_details =<<<EOD
<table width="80%" border="1" cellspacing="2"
cellpadding="2" align="center">
<tr>
<th colspan="6"><u><h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<td width="20%" 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 width="95%" border="0" cellspacing="2"
cellpadding="20" aling="center">
$review_table_heading
$review_details
</table>
EOD;
}
$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++;
}
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
$page_start
$movie_details
$page_end
EOD;

echo $detailed_movie_info;
mysql_close();

?>

 
Put this at the bottom of the page to see what value you get:

echo $review_flag;

Lee
 

I think it's just a syntax error:
Code:
$review_query = "select * from reviews " .
"where review_movie_id ='" . [COLOR=red][b]$[/b][/color] $_GET['movie_id'] . "' " .
"order by review_date desc";

Get rid of the extra $ and you should get a recordset back from your query... and everything ought to come to life.

Hope so anyway!
Jeff
 
Thank you guys for the quick response. It was a syntax error.

$ $_GET['movie_id'] . "' " .
also
cellpadding="20" aling="center">


I figured it out this morning but I also noticed babyjeffy found it also.

The worst thing about my solution was it took two days of rewriting code and trying to find the error.

I really appreciate the quick responses I get from this forum.

Since, I am new at php I was just curious if there was some kind of program/text editor/compiler that would catch errors such as these. I know thats probably a stupid question but who knows.

Thanks again guys.
 

Well... not really that I know of... I tend to make generous use of the echo command as I am building up a solution. Most of my errors tend to be forgetting to put in the semi-colons or, like you, getting no data back from queries that I "know" should work.

Using echo mysql_error(); after a mySQL command is also a great help (it ought to return 0 if there were no errors... otherwise an error code is shown). Really handy for testing mySQL syntax errors (don't leave it in for production).

Using a text editor with colour syntax hilighting is handy too. I program PHP on MacOSX mostly... and use the free TextWrangler (from Bare Bones - who sell BBEdit) which has wonderful colourisation (for php as well as others). When I'm working on a Windows machine I tend to use TextPad (shareware) - which also provides support for colourisation.

Cheers,
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top