Welcome Guest, Not a member yet? Register   Sign In
MSSQL offset workaround
#1

[eluser]faceh[/eluser]
I have found a few topics on this forum regarding MSSQL pagination, but didn't find anybody listing the following as a workaround. Looking at the limit() method for the mssql driver, Codeigniter takes your db->limit($limit, $offset) call and converts it to limit($limit + $offset) with no offset.

So, my workaround is to use array_slice() to chop off and return the end of the array, starting from the $offset.

Is this a terrible way to do things? I can see it being a bit slow with databases with 1000s of records as you are working with huge arrays, but from what I can see of the other SQL query hacks for MSSQL pagination, they dont look too pretty/efficient either...

Example:
Code:
// Set the offset / limit
$start = is_numeric($start) ? $start : 0;
$limit = is_numeric($limit) ? $limit : 0;
$this->MSSQL->limit($limit, $start);

// Perform the query
$query = $this->MSSQL->get();

// Return only the slice of the result set that we want
return array_slice($query->result(), $start, $limit);
#2

[eluser]whobutsb[/eluser]
I can see myself using this for returning row ID numbers and doing a loop foreach of the ID numbers to get that actual data. But I wouldn't want to return 1000's of rows with lots of data in them.




Theme © iAndrew 2016 - Forum software by © MyBB