Drop-down filter menu
Posted: Wed May 09, 2007 2:58 pm
Im trying to add a form which filters the content of a table displayed when the visitor selects a category from the drop-down menu.
At the moment I get a parse error unexpected ;, Ive highlighted the bracket in question with a comment. Im still very much a PHP beginner, so please let me know if im going in the right direction and where to go next.
At the moment I get a parse error unexpected ;, Ive highlighted the bracket in question with a comment. Im still very much a PHP beginner, so please let me know if im going in the right direction and where to go next.
Code: Select all
//Basic Form
<form action="main.php" method="post">
<select name="gid">
<option selected value="">Genre</option>
</form>
Code: Select all
//Connecting to database
$Host = "localhost";
$User = "username";
$Password = "password";
$Database = "databasename";
$Link_ID=mysql_pconnect($Host, $User, $Password);
if (!$Link_ID)
{
echo "Failed to connect to Server=".$Host;
return 0;
}
else
{
# echo "<B>Successfully to connected to Server </B>" .$Host;
}
if (!@mysql_select_db($Database,$Link_ID))
{
# echo "<br>Cannot use database= " .$Database;
}
else
{
# echo "<br> Successfully connected to database= ";
}
//Setting variables and looping through selection
$genres = @mysql_query ('select genre_id, genres from genre_ids');
if (!$genres) {
exit('<p>unable to obtain genre list from database.</p>';
} // <<<<<<parse error here
while ($genre = mysql_fetch_array($genres)) {
$gid = $genre['genre_id'];
$gname = htmlspecialchars($genre['genres']);
echo "<option value='$gid'>$gname</option>\n;
}
// Performing SQL query when no category has been selected
$query = "SELECT dvd_titles.dvd_id // <<<<<<parse error here
, dvd_title
, ROUND((coalesce(sum(totalfilm),0)
+coalesce(sum(empire),0)
+coalesce(sum(radiotimes),0)
+coalesce(sum(independent),0)
+coalesce(sum(mirror),0)
+coalesce(sum(guardian),0)
) /
coalesce( count(totalfilm)
+count(empire)
+count(radiotimes)
+count(independent)
+count(mirror)
+count(guardian)
),1) as rounded_rating
, prodn_year
, date_format(dvd_rlsdate,'%d %b %y') as rlsdate
, dvd_genre
, totalfilm
, empire
, radiotimes
, independent
, mirror
, guardian
FROM dvd_titles
, dvd_genres
, critics_ratings
WHERE dvd_genres.dvd_id=dvd_titles.dvd_id
AND dvd_titles.dvd_id=critics_ratings.dvd_id
GROUP BY dvd_titles.dvd_id
ORDER BY dvd_title";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo '<table>';
echo '<table class="sortable" preserve_style="cell" id="maintable">';
echo "<thead><tr><th>Title</th><th>Avg.<br>Rating</th><th>Year</th><th>DVD<br>Release Date</th><th>Main Genre</th><th>TF</th><th>EM</th><th>RT</th><th>ID</th><th>MR</th><th>GN</th></tr></thead>"; // Setting Column Names
while( $row=mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo '<tbody><tr>',
'<td><a href="detail.php?id=', $row['dvd_id'], '">', htmlentities($row['dvd_title']), '</a></td>',
'<td>', htmlentities($row['rounded_rating']), '</td>',
'<td>', htmlentities($row['prodn_year']), '</td>',
'<td>', htmlentities($row['rlsdate']), '</td>',
'<td>', htmlentities($row['dvd_genre']), '</td>',
'<td>', htmlentities($row['totalfilm']), '</td>',
'<td>', htmlentities($row['empire']), '</td>',
'<td>', htmlentities($row['radiotimes']), '</td>',
'<td>', htmlentities($row['independent']), '</td>',
'<td>', htmlentities($row['mirror']), '</td>',
'<td>', htmlentities($row['guardian']), '</td>',
'</tr></tbody>';
}
echo '</table>';
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($Link_ID);
?>