I have a PHP script that outputs a list of reviews in a table and orders them by the date they were submitted - (similar to have Trip Advisor ratings work).
Below I have included how the table heading are set out:
NAME || DATE || REVIEW || RATING
Below I have listed the code:
//run a query to find all the fields in the review table that belong to the specific hall, using the id in the url ($current_id)
if ($r = $db->prepare("SELECT * FROM reviews WHERE hall_id = :current_id ORDER BY overall DESC")) {
//bind the parameters used in the above query using the 'current_id' variable
$r->bindParam(':current_id', $current_id);
//Execute the prepared query
$r->execute();
//search review table for all fields and save them in $review
$reviewtemp = $r->fetchAll();
foreach( $reviewtemp as $review) { ...
ORDER BY date DESC
orders the reviews by the date. However, when the user clicks on the 'RATING' header in the table, I need the reviews to be ordered by the highest rating (which is a number). So ORDER BY date DESC
would change into ORDER BY rating DESC
.
I'm unsure whether I have to create an entire new page (and simply change 1 word of my php script) to do this, or if there is a more simple and efficient method?