agh
agh

Reputation: 409

zend paginator with random sorting

Is it possible to use zend paginator on a mysql query with random ordering?

I'm struggling to wrap my head around this one.

Upvotes: 2

Views: 520

Answers (3)

anoe
anoe

Reputation: 1

You can use ORDER BY RAND({seed}), as explained here (with zend integration).

Upvotes: 0

Marcin Hubert
Marcin Hubert

Reputation: 589

It is possible with mysql rand(n) function.

"n is used as the seed value, which produces a repeatable sequence of column values"

So simply add to your select - for example SELECT rand(21) AS ord FROM TABLE ORDER BY ord and every time you wand different set of results, just change 21 to something else.

http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand

Upvotes: 0

Tim Fountain
Tim Fountain

Reputation: 33148

ORDER BY RAND() will (unsuprisingly) return random results each time it is run, so you won't be able to paginate this in the normal way.

You would have to select ALL the data in the first run, record the order of the elements and use this on any subsequent pages. Alternatively you could just select all the data and do the pagination with Ajax. Either approach would be a fair bit of work.

Upvotes: 3

Related Questions