0

Hello,

i have some problem with this issue. i have to do display results randomly using mysql. but results don't repeat until one cycle completed.

i mean there are 6 results is there....

example first displyed randomly like 2 and 6, next 3 , 4 next 1,5 (one cycle completed)
again displaying randomly like 2 and 4, next 3,5 next 1,6 (cycle completed)

but not repeat result until cycle complete.


Any body help me.

thanks.

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by pritaeas
0

You can add an extra integer column to your table. Select two (using LIMIT) random items where you order the query by MIN(extra column) first, and RAND() second. After using the selected two, increment the extra field.

0

sorry i did not get you. if you don't mind please explain. what is the use of extra column.

you mean like this: SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 1;

Edited by muralikalpana: n/a

0

Define an extra column (integer).

SELECT * FROM table ORDER BY MIN(extra), RAND() LIMIT 2

Now you get two results. For each of them, increment the extra column by 1. Next time, using the same query, you will get two different results. Suppose you have six items in the table, after the third query, all values in the extra column are set to 1, so all options are equally available again.

Edited by pritaeas: n/a

0

i understood but i have 1000s of results. then is there any problem will occur on pageloads. i mean slow loading.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.