How to pre-filter the initial presentation of a listing

nicholashg 11 Dec, 2010
I'm sure this is a common requirement but I can't find any guidance and my attempts at a solution have so far failed.

I have tables, user-filtered listings, and forms all linking backwards and forwards and working well (based largely on Greyhead's tutorials - a life-saver).

What would be the best way to impose initial filtering criteria to a listing (for example get the latest 20 submissions) in order not to load ALL (potentially 000s) of records? This would not be a user input but simply a temporary constraint that would be released once it has done its job.

The user input fields obviously have to be present to allow the user to move forwards.
GreyHead 11 Dec, 2010
Hi nicholashg,

I've never had to do this but here's a suggestion.

Add an extra Where clause in the WHERE box but make it conditional on checking a session variable. If the variable isn't present then set the Where clause, put the variable in the session and skip the rest of the WHERE box code.
<?php

$session =& JFactory::getSession();
$been_here_before = $session->get('been_here_before', 0);
if ( !$been_here_before ) {
  $where = "WHERE . . .";
  $session->set('been_here_before', 1);
} else {
  . . .
}
echo $where;
?>

Bob

PS Provided that you don't have an entry in the Order By box you can append ORDER BY `xxx` DESC to the Where clause.
nicholashg 11 Dec, 2010
Hello Bob,
Nice approach, just the job. I'll let you know how it works out.
Thank you,
Nick
This topic is locked and no more replies can be posted.