views:

98

answers:

1

I am trying to sort a list of movie reviews in chronological order. We have two options users can choose from, chronological and alphabetical. The page defaults to alphabetical, 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 the two ifs. Putting GetArticles first and GetArticlesABC second- meaning it looked 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);
                }

It did indeed sort the reviews chronologically but it took away all of the alphabetical options. Essentially it was a long list of chronological reviews. So obviously that's not what we want.

Does anyone know how to limit the number of items that it lists on the page? Or maybe a completely different approach is needed here, if so, any suggestions?

+1  A: 

Limiting the number of results per page, if using a backend database and SQL is as simple as using the LIMIT operator to only retrieve a set number of results. You can then implement next/previous operations by passing a variable between pages which relates to the set of results you have 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

Will retrieve the next 10. By substituting the numbers with variables you can achieve pagination:

SELECT <Whatever> FROM <review table> LIMIT resultIndex,resultIndex+10
Jamie Lewis
Thanks, that should work perfectly.
Iwasakabukiman