Forum Moderators: coopster

Message Too Old, No Replies

Can one mysql select use data across multiple pages?

Not paging. One select only - but data from this split into multiple pages

         

whitenoise

3:46 pm on Aug 9, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi everyone,

I'm sorry if this has been asked before, but I can't seem to find an answer to my problem.

Basically I want to have say 50 'pages' (although it would just be resubmitting to itself) where each page grabs data from one random row. I could do this simply by choosing a random row and then getting the data for that random row and displaying it. However, this would mean having 50 select statements and would really slow things down. I cannot pre-generate the random sequence and pass it with the URL as it needs to be hidden. I looked into paging, but this just does what I have already, performing a select for each page.

Is there anyway how I can just do one select query to grab the data for all 50 rows, and then use a row of this data one at a time for each page? Hopefully this makes sense! Thanks for any help =)

FalseDawn

9:26 pm on Aug 9, 2006 (gmt 0)

10+ Year Member



I'm not quite sure what you are trying to do, but look into using the ORDER BY RAND() and LIMIT 50 constructs maybe?

Be aware that ORDER BY RAND() is horrendously inefficient in certain cases and it would be better to dynamically build a query with 50 random key values pre-generated (a,b,c,d etc), then use a SELECT * FROM blah WHERE KEY IN(a,b,c,d...) for example, depending on how exacly your primary key field is constructed and the distribution of values within it.

whitenoise

8:43 am on Aug 10, 2006 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks FalseDawn for the information. An idea stuck me not long after I posted so I might try that out. Thanks again.