Hi!
I read everithig abou pagination in this forum and in documentation.
I have a function that is caracterise by a query that show me 244 results.
Function resturn query results.
I need divide my result (10 for every page).
I see http://doc.silverstripe.org/doku.php?id=tutorial:4-site-search but I can reate something correct to show my result in my template. Cany you help me?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hello bebabeba!
Are you still having trouble with pagination? If so, I could get it working today. I'm getting my Query results from an external database as well; I got some help from the IRC and I did it today.
I created two functions, one that returns my whole data and other that returns just the range of data a want in every page. My first function is as follow:
Public function GetSelectedAvailable(){
global $product;
$selectedprd;
global $SQL_start;
global $Length;
if (isset($product)) $selectedprd = $product;
if (!isset($product)) $selectedprd = Session::get('product');
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$db = $this->connect();
$sql="SELECT `AvailabilityMaster`.`Desc`, `Stylecodes`.`Style`, `AvailabilityRaw`.`Qty`, `AvailabilityRaw`.`Price`
FROM (`AvailabilityRaw`
LEFT JOIN AvailabilityMaster
ON AvailabilityRaw.IDcode = AvailabilityMaster.IDcode)
LEFT JOIN Stylecodes
ON AvailabilityMaster.StyleCode = Stylecodes.code
WHERE `AvailabilityRaw`.`product` ='".$selectedprd."'";
$query = $db->query($sql);
$result = new DataObjectSet();
foreach($query as $row) {
$result->push(new ArrayData($row));
}
$Length = 10;
//Set Page Limits
$result->SetPageLimits($SQL_start,$Length,$result->Count());
return $result;
}
I declared two global variables ($SQL_start and $Length) that I'm using for SetPageLimits, and I will use them also in my function that will return the range of items to display in each page. This function is the next one:
Public function GetSelectedRange(){
global $SQL_start;
global $Length;
$result = New DataObjectSet();
$result = $this->GetSelectedAvailable();
$result = $result->getRange($SQL_start,$Length);
return $result;
}
In this function I just declared a new DataObjectSet, and then passed the result from the function that returns everything and then I filter it using $result->getRange(). And passing the values that are stored in the global variables.
I hope this will help.
Bye.