Sort the list of reviews in chronological order
I am trying to sort the list of movie reviews in chronological order. We have two options that users can choose from: chronological and alphabetical. The default is for alphabetical pages, but when people click on the chronological option, nothing happens.
Here is the code we have right now:
// category 3 is 'reviews', category 12 is 'dvd reviews'
if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
{
$output = AL_HELPER::GetArticles($articleResult);
}
else
{
$output = AL_HELPER::GetArticlesABC($articleResult);
}
What I did was flip flop. First let's add GetArticles and GetArticlesABC in the second - it looks like this:
// category 3 is 'reviews', category 12 is 'dvd reviews'
if (($GLOBALS["CategoryId"] == 3 || $GLOBALS["CategoryId"] == 12) && !isset($_GET['unsort']))
{
$output = AL_HELPER::GetArticlesABC($articleResult);
}
else
{
$output = AL_HELPER::GetArticles($articleResult);
}
He did sort the reviews in chronological order, but he selected all the options in alphabetical order. It was essentially a long list of chronological overviews. So obviously we don't want to.
Does anyone know how to limit the number of items it lists on a page? Or maybe a completely different approach is needed here, if so, any suggestions?
source to share
Limiting the number of results per page when using the underlying database and SQL is as simple as using the LIMIT clause just to get a given number of results. Then you can implement the following / previous operations by passing the variable between pages associated with the result set you pulled.
For example:
SELECT <Whatever> FROM <review table> LIMIT 0,10
Will retrieve the first 10 results.
SELECT <Whatever> FROM <review table> LIMIT 10,20
Retrieves the following 10. By swapping numbers with variables, you can achieve pagination:
SELECT <Whatever> FROM <review table> LIMIT resultIndex,resultIndex+10
source to share