开发者

zend paginator with random sorting

Is it possible to use zend paginator on a mysql qu开发者_开发知识库ery with random ordering?

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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜