My query is
SELECT * FROM `businesses` ORDER BY RAND() LIMIT $startResults, $perPage
So how do I make all the results random, but not sure duplicate results on the other pages?
Posted 03 February 2013 - 05:12 PM
SELECT * FROM `businesses` ORDER BY RAND() LIMIT $startResults, $perPage
Posted 03 February 2013 - 05:18 PM
serialize () the array with the results from the query (without the LIMIT clause), and then save it to a file or temporary table. However you control access to that file/table, say one per user, for instance, or how long it should be available, is completely up to you.Edited by Christian F., 03 February 2013 - 05:19 PM.
Posted 03 February 2013 - 07:46 PM
$query = "SELECT * FROM `businesses` ORDER BY RAND($random) LIMIT $startResults, $perPage";
Edited by requinix, 03 February 2013 - 07:47 PM.
Posted 05 February 2013 - 01:07 AM
If you like my reply please click on https://plus.google....w.p5systems.com to approve it.
Thanks,
P5 Systems
http://www.p5systems.com/
Posted 05 February 2013 - 03:30 AM
Unless there are 1M rows to consider. Or even 10K.Take the results in an array. An use array pagination it will work
Edited by requinix, 05 February 2013 - 03:32 AM.
Posted 05 February 2013 - 03:05 PM
Posted 05 February 2013 - 03:10 PM
Posted 05 February 2013 - 06:17 PM
Posted 05 February 2013 - 06:23 PM
Posted 05 February 2013 - 06:33 PM
Posted 05 February 2013 - 08:26 PM
If you do the seeded-RAND() I mentioned then the order will change a bit: rows located earlier that the deleted record will sort the same relative to each other, but rows after the deleted record will appear randomly interspersed. At least in MySQL 5.5.Not quite seeing the problem you're describing, Psycho. Either method described would pull the full number of results on page 3, the only difference would be whether or not you'd see the deleted record as well.
mysql> create table test (a int); Query OK, 0 rows affected (0.12 sec) mysql> insert into test values (1),(2),(3),(4),(5),(6),(7),(<img src='http://forums.phpfreaks.com/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='8)' />,(9),(10); Query OK, 10 rows affected (0.03 sec) Records: 10 Duplicates: 0 Warnings: 0 mysql> select * from test order by rand(123); +------+ | a | +------+ | 6 | | 4 | | 9 | | 8 | | 2 | | 10 | | 3 | | 5 | | 1 | | 7 | +------+ 10 rows in set (0.06 sec) mysql> delete from test where a=10; Query OK, 1 row affected (0.03 sec) mysql> select * from test order by rand(123); +------+ | a | +------+ | 6 | | 4 | | 9 | | 8 | | 2 | | 3 | | 5 | | 1 | | 7 | +------+ 9 rows in set (0.03 sec) mysql> delete from test where a=5; Query OK, 1 row affected (0.04 sec) mysql> select * from test order by rand(123); +------+ | a | +------+ | 7 | | 4 | | 9 | | 2 | | 3 | | 6 | | 1 | | 8 | +------+ 8 rows in set (0.04 sec)
Posted 07 February 2013 - 10:44 AM
If you do the seeded-RAND() I mentioned then the order will change a bit: rows located earlier that the deleted record will sort the same relative to each other, but rows after the deleted record will appear randomly interspersed. At least in MySQL 5.5.
Posted 08 February 2013 - 11:27 PM
Posted 12 February 2013 - 04:28 AM
0 members, 0 guests, 0 anonymous users