|
Posted by David Haynes on 02/27/06 13:29
universalbitmapper wrote:
> Hi,
>
> This exercise (From PAM525Web Development) asks me to display a table
> of reviews, then sort the reviews depending on which column heading is
> clicked.
>
> I can't find how to write this line:
>
> <th><a
> href=movie_details03.php?movie_id=$movie_id&coll_sort=\"review_date\">"Date
> of Review"</th>
>
> in this bit of code:
>
> $review_table_headings=<<<EOD
> <tr>
> <th><a
> href=movie_details03.php?movie_id=$movie_id&coll_sort=\"review_date\">"Date
> of Review"</th>
> <th>Review Title</th>
> <th>Reviewer Name</th>
> <th>Movie Review Comments</th>
> <th>Ratings</th>
> </tr>
> EOD;
>
> The coll_sort variable is extracted by a GET
>
I may have this screwed up, but isn't this just a case of setting a
default sort order and 'href'fing the headers?
If so, the form needs some top processing...
<?php
// use the specified column for sorting or sort by ratings by default
$coll_sort = isset($_GET['coll_sort']) ? $_GET['coll_sort'] : 'rating';
// select and order based on coll_sort
$sql = <<<SQL
select
movie_id,
title,
name,
comment,
rating
from
reviews
order by
$coll_sort;
$result = ....
I've assumed a database-backed form here. If this is just an array, then
you would use array sorts to do the same thing.
Then you would need to change the references to 'Review Title',
'Reviewer Name', etc. to be href links that set the coll_sort.
For example:
<th><a
href="movie_details03.php?movie_id=$movie_id&coll_sort=title">Review
Title</th>
Notes:
Make the coll_sort value match the column name in the database unless
you are worried about exposing that level of implementation detail to
the user. If so, make sure to map the coll_sort name into a database
column name before you do the query.
There is no need to use the double quotes around the argument to
coll_sort in your href. The entire href= argument is already quoted.
Hope this helps.
-david-
[Back to original message]
|