tito85 Posted May 28, 2010 Share Posted May 28, 2010 Hi Everyone, I am new here... I would like some help resolving an issue I have with this code. On line 86 i have an echo to output all the genres a movie has. However only one genre is being outputted. I've tested the query in MySQL using PHPMyAdmin and is working fine. I guess I have a mistake with the { or } but I cannot find where. Any help would be veru helpful. Thanks <?php require('dbconnect.php'); session_start(); ?> <?php if (isset($_POST['btnSubmitComment'])) { $body = mysql_real_escape_string($_POST['txtMessage']); if (strlen(trim($body)) > 0) { $query = "INSERT INTO comments (Comment, UserID, PostDateTime, MovieID) VALUES ('" . $body . "', '" . $_SESSION['userinfo']['id'] . "', '" . date("Y-m-d H:i:s") . "', '" . $_GET['id'] . "')"; mysql_query($query); } else { $message = "Error: <b>Body</b> is mandatory"; } } if (isset($_POST['btnSubmitRating'])) { $rating = $_POST['ddlRating']; if ($rating != "0") { $query = "INSERT INTO ratings (UserID, MovieID, Rating) VALUES ('" . $_SESSION['userinfo']['id'] . "', '" . $_GET['id'] . "', '" . $rating . "')"; mysql_query($query); } else { $message2 = "Error: <b>Select Rating</b>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Online Movie Database - Movie Details</title> <link rel="stylesheet" href="CSSWebStyles/style.css" /> <link rel="shortcut icon" href="Images/filmicon.ico" /> </head> <body> <div id="website"> <?php //This will include the top banner of the WebSite include('banner.php'); ?> <?php //This will check if the user is an Administrator if (isset($_SESSION['superadmin'])) { if ($_SESSION['superadmin']) include('adminmenu.php'); } ?> <div id="content"> <div id="contentleft2"> <br /> <center> <h2>Movie Details</h2> </center> <br /> <?php if (isset($_GET['id'])) { $select = "SELECT genretypes.*, genres.*, movies.* FROM movies INNER JOIN genres ON genres.MovieID = movies.MovieID INNER JOIN genretypes ON genres.GenreTypeID = genretypes.GenreTypeID WHERE movies.MovieID = '" . $_GET['id'] . "' ORDER BY movies.MovieID"; $result = mysql_query($select); if (mysql_num_rows($result) > 0) { while ($movies = mysql_fetch_array($result)) { echo "<div style=\"overflow: auto;\">"; echo "<center><h3>" . stripslashes($movies['Title']) . "</h3></center>"; echo "<br><br>"; echo "<div style=\"float: right; padding-right: 150px; height: 400px; \">"; if (strlen($movies['Filename']) > 0) { echo '<img src="Images/Movies/' . $movies['Filename'] . '" width="246" height="365" />'; } echo "</div>"; echo "<div style=\"float: left; padding-left: 150px; padding-top: 50px; \">"; ?> <table> <tr height="40"> <td align="right"> <strong>Director/s: </strong> </td> <td> <?php echo $movies['Director1']; ?> </td> <td> <?php echo $movies['Director2']; ?> </td> </tr> <tr height="40"> <td align="right"> <strong>Genre: </strong> </td> <td> <?php echo $movies['Genre']; ?> </td> </tr> <tr height="40"> <td align="right"> <strong>Rating: </strong> </td> <td> <?php if ($movies['Rating'] == 0) echo "N/A"; else echo $movies['Rating']; ?> <?php if ($movies['Rating'] == 0) echo ""; else echo "/10"; ?> </td> </tr> <tr height="40"> <td align="right"> <strong>Movie Release Date: </strong> </td> <td> <?php if (date("d/m/Y", strtotime($movies['MovieReleaseDate'])) == "01/01/1970") echo "N/A"; else echo date("d/m/Y", strtotime($movies['MovieReleaseDate'])); ?> </td> </tr> <tr height="40"> <td align="right"> <strong>DVD Release Date: </strong> </td> <td> <?php if (date("d/m/Y", strtotime($movies['DVDReleaseDate'])) == "01/01/1970") echo "N/A"; else echo date("d/m/Y", strtotime($movies['DVDReleaseDate'])); ?> </td> </tr> <?php if (isset($_SESSION['user']) && $_SESSION['user'] == true) { ?> <tr height="40"> <?php $select = "SELECT * FROM favorites WHERE UserID = " . $_SESSION['userinfo']['id'] . " AND MovieID = " . $_GET['id']; $isfavorite = mysql_query($select); if (mysql_num_rows($isfavorite) == 0) { ?> <td colspan="2" align='center'><a href="addtofavs.php?id=<?php echo $movies['MovieID'] ?>">Add this Movie to my Favorite Movies</a></td> <?php } else { ?> <td colspan="2" align='center'><a href="removefromfavs.php?id=<?php echo $movies['MovieID'] ?>">Remove this Movie from my Favorites Movies</a></td> <?php } ?> </tr> <?php } ?> </table> <?php echo "</div>"; //checking if current logged in user is an admin if (isset($_SESSION['user']) && $_SESSION['superadmin'] == true) { echo "<div style=\"; clear: both;\"><a onclick=\"return confirm('Are you sure you want to Edit this Movie Information?');\" href=\"editmovie.php?id=" . $movies['MovieID'] . "\">Edit</a> / <a onclick=\"return confirm('Are you sure you want to Delete this Movie from the Database?');\" href=\"deletemovie.php?id=" . $movies['MovieID'] . "\">Delete</a></div>"; } echo "</div>"; echo "<br><br>"; //Review echo "<div class=\"blog2\"><h4 style=\"margin: 0\">Movie Review</h4><p />"; if (strlen($movies['Review']) > 0) { echo (nl2br($movies['Review'])); } else { echo "No review is available for this Movie"; } echo "</div>"; ?> <?php //Comments echo "<div class=\"blog2\"><h4 style=\"margin: 0\">User Comments</h4><hr style=\"border: 1px solid #06C\" />"; $query = "SELECT c.*, u.Username, u.UserID AS userid FROM comments c INNER JOIN users u ON u.UserID = c.UserID WHERE c.MovieID = '" . $_GET['id'] . "' ORDER BY PostDateTime DESC"; $result = mysql_query($query); while ($comment = mysql_fetch_array($result)) { echo "On " . date("d/m/Y", strtotime($comment['PostDateTime'])) . " <b><a href=\"userdetails.php?id=" . $comment['userid'] . "\">" . $comment['Username'] . "</a></b> said:<br />"; echo $comment['Comment']; echo "<hr style=\"border: 1px solid #06C\" />"; } if (isset($_SESSION['user'])) { echo "<p /><b>Submit your comment:</b>"; ?> <form method="post"> <?php if (isset($message)) { echo "<center>$message</center>"; unset($message); } ?> <table> <tr> <td valign="top"> Message: </td> <td> <textarea rows="5" cols="50" name="txtMessage"></textarea> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" value="Submit" name="btnSubmitComment" /> </td> </tr> </table> </form> <?php } echo "</div>"; ?> <?php //Rating echo "<div class=\"blog2\"><h4 style=\"margin: 0\">Average User Rating</h4><hr style=\"border: 1px solid #06C\" />"; $query = "SELECT SUM(Rating)/COUNT(0) AS averagerating FROM ratings r WHERE r.MovieID = '" . $_GET['id'] . "'"; $averagerating = mysql_query($query); $query = "SELECT COUNT(0) AS ratingsgiven FROM ratings r WHERE r.MovieID = '" . $_GET['id'] . "'"; $count = mysql_query($query); echo "The average user rating of this movie is: <b>"; if (mysql_result($averagerating, 0, 'averagerating')) { echo round(mysql_result($averagerating, 0, 'averagerating'), 1); } else echo "0"; echo "/10</b><p />"; echo "<b>" . mysql_result($count, 0, 'ratingsgiven') . "</b> user/s submitted their rating to this movie<hr style=\"border: 1px solid #06C\" />"; ?> <?php //Checking if user submitted his rating already if (isset($_SESSION['user'])) { $query = "SELECT * FROM ratings WHERE UserID = '" . $_SESSION['userinfo']['id'] . "' AND MovieID = '" . $_GET['id'] . "'"; $result = mysql_query($query); if (mysql_num_rows($result) > 0) { echo "You already submitted your rating to this movie<p />"; echo "Your Rating is: <b>" . mysql_result($result, 0, 'Rating') . "/10</b>"; } else { echo "<p /><b>Submit your rating:</b>"; ?> <form method="post"> <?php if (isset($message2)) { echo "<center>$message2</center>"; unset($message2); } ?> <table> <tr> <td valign="top"> Rating: </td> <td> <select name="ddlRating"> <option value="0">Please Select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" value="Submit" name="btnSubmitRating" /> </td> </tr> </table> </form> <?php } } echo "</div>"; ?> <?php //Recommendations echo "<div class=\"blog2\"><h4 style=\"margin: 0\">We Recommend this Movie for you:</h4><p />"; echo "<hr style=\"border: 1px solid #06C\" />"; $query = "SELECT * FROM movies WHERE GenreID = " . $movies['GenreID'] . ") AND MovieID != " . $movies['MovieID'] . " AND Rating != 0 ORDER BY RAND() LIMIT 0,5"; $recommendations = mysql_query($query); if (mysql_num_rows($recommendations) > 0) { echo "<table align=\"center\"><tr>"; while ($recommendation = mysql_fetch_array($recommendations)) { echo "<td><a href=\"moviedetails.php?id=" . $recommendation['MovieID'] . "\">" . '<img src="Images/Movies/' . $recommendation['Filename'] . '" width="125" height="185" />' . "</a></td>"; } echo "</tr></table>"; } echo "</div>"; } ?> <?php } else { echo "<center><b>The movie you are trying to access does not exist</b></center>"; } } ?> </div> </div> <?php //will include the code from footer.php file include('footer.php'); ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/203186-outputting-query-result/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.