RE: [PHP-DB] Random Selecting from mySQL
Hi! Do you have a primary key field in the table? If yes, you can after displaying the first 10 records you can put the primary key values of those records in an array and have "primary_key_fiels NOT IN (array_values_seperated_by_commas)" in your quesry.. So when you display your first page with 10 records, then you won't have any restricting values because the array will be empty. When you display it second time then you will have the first 10 records excluded and your array will be populated 20 values so that when you display the third page thos 20 will be excluded and vice versa.. Did I confuse you enough?:) I hope this helps.. Gurhan -Original Message- From: Georgie Casey [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 7:11 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] Random Selecting from mySQL yea, i know how to display 10 results per page, but that doesnt work when you want to do a ORDER BY rand() query. "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > are you just looking for a way to display 10 results per page? If yes then > you can just use LIMIT to limit your result to 10 .. So, for the first page, > you can do "SELECT LIMIT 1, 10;" and for the second page "SELECT ... > LIMIT 11, 20" etc etc . > You can sure use "ORDER BY" with "LIMIT" to to sort the results for a > given criteria .. > > Gurhan > > > -Original Message- > From: Georgie Casey [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 13, 2002 2:00 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: [PHP-DB] Random Selecting from mySQL > > > I know how to use the "ORDER BY rand()" command on the end of queries to > randomize selection, but that's no good when you want to only display 10 > results per page. The next page the user chooses, randomizes again and could > show duplicate fields and not at all show other fields. > > Does anyone know a way round this? > > -- > Regards, > Georgie Casey > [EMAIL PROTECTED] > > *** > http://www.filmfind.tv > Ireland's Online Film Production Directory > *** > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Random Selecting from mySQL
Hi, You might try something like this: 1) Create a temporary table in MySQL using the data from the table you are selecting from. 2) On each page, do your select with "order by rand() limit 10" from the temporary table 3) Do a second query to delete the rows that you just selected from the temporary table 4) On the next page, go back to step 2. Syntax for copying a table into an identical temporary table: CREATE TEMPORARY TABLE my_tbl SELECT * FROM tbl (courtesy of "MySQL" by Paul DuBois). /bsh/ Beau Lebens wrote: >could you perhaps do the select on the first page, then store the results in >a session (array) and just load different indexed portions of the resultset >each page? > >only problem there is that you wouldn't get any refreshed results while >browsing those pages - but i don't know if this matters for you or not. > >HTH > >Beau > >// -Original Message- >// From: Georgie Casey [mailto:[EMAIL PROTECTED]] >// Sent: Thursday, 14 March 2002 3:00 AM >// To: [EMAIL PROTECTED]; [EMAIL PROTECTED] >// Subject: [PHP-DB] Random Selecting from mySQL >// >// >// I know how to use the "ORDER BY rand()" command on the end >// of queries to >// randomize selection, but that's no good when you want to >// only display 10 >// results per page. The next page the user chooses, randomizes >// again and could >// show duplicate fields and not at all show other fields. >// >// Does anyone know a way round this? >// >// -- >// Regards, >// Georgie Casey >// [EMAIL PROTECTED] >// >// *** >// http://www.filmfind.tv >// Ireland's Online Film Production Directory >// *** >// >// >// >// -- >// PHP Database Mailing List (http://www.php.net/) >// To unsubscribe, visit: http://www.php.net/unsub.php >// > -- /-=[ BILLY S HALSEY ]=--\ | Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW | | "All opinions and technical advice offered in this message are my | | own and not necessarily endorsed by my employer." | \--=[ [EMAIL PROTECTED] ]=/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Random Selecting from mySQL
Pass along a hidden form which documents exactly what rows have already been shown then you could use $seen=explode(':', $seen); to break it into an array... after that use a foreach to add a 'and id != '.$seen into the sql query for every element in $seen... thus not allowing duplicates on a per visit basis... -Original Message- From: Georgie Casey [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 4:11 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] Random Selecting from mySQL yea, i know how to display 10 results per page, but that doesnt work when you want to do a ORDER BY rand() query. "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > are you just looking for a way to display 10 results per page? If yes then > you can just use LIMIT to limit your result to 10 .. So, for the first page, > you can do "SELECT LIMIT 1, 10;" and for the second page "SELECT ... > LIMIT 11, 20" etc etc . > You can sure use "ORDER BY" with "LIMIT" to to sort the results for a > given criteria .. > > Gurhan > > > -Original Message- > From: Georgie Casey [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 13, 2002 2:00 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: [PHP-DB] Random Selecting from mySQL > > > I know how to use the "ORDER BY rand()" command on the end of queries to > randomize selection, but that's no good when you want to only display 10 > results per page. The next page the user chooses, randomizes again and could > show duplicate fields and not at all show other fields. > > Does anyone know a way round this? > > -- > Regards, > Georgie Casey > [EMAIL PROTECTED] > > *** > http://www.filmfind.tv > Ireland's Online Film Production Directory > *** > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Random Selecting from mySQL
could you perhaps do the select on the first page, then store the results in a session (array) and just load different indexed portions of the resultset each page? only problem there is that you wouldn't get any refreshed results while browsing those pages - but i don't know if this matters for you or not. HTH Beau // -Original Message- // From: Georgie Casey [mailto:[EMAIL PROTECTED]] // Sent: Thursday, 14 March 2002 3:00 AM // To: [EMAIL PROTECTED]; [EMAIL PROTECTED] // Subject: [PHP-DB] Random Selecting from mySQL // // // I know how to use the "ORDER BY rand()" command on the end // of queries to // randomize selection, but that's no good when you want to // only display 10 // results per page. The next page the user chooses, randomizes // again and could // show duplicate fields and not at all show other fields. // // Does anyone know a way round this? // // -- // Regards, // Georgie Casey // [EMAIL PROTECTED] // // *** // http://www.filmfind.tv // Ireland's Online Film Production Directory // *** // // // // -- // PHP Database Mailing List (http://www.php.net/) // To unsubscribe, visit: http://www.php.net/unsub.php // -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Random Selecting from mySQL
yea, i know how to display 10 results per page, but that doesnt work when you want to do a ORDER BY rand() query. "Gurhan Ozen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > are you just looking for a way to display 10 results per page? If yes then > you can just use LIMIT to limit your result to 10 .. So, for the first page, > you can do "SELECT LIMIT 1, 10;" and for the second page "SELECT ... > LIMIT 11, 20" etc etc . > You can sure use "ORDER BY" with "LIMIT" to to sort the results for a > given criteria .. > > Gurhan > > > -Original Message- > From: Georgie Casey [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 13, 2002 2:00 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: [PHP-DB] Random Selecting from mySQL > > > I know how to use the "ORDER BY rand()" command on the end of queries to > randomize selection, but that's no good when you want to only display 10 > results per page. The next page the user chooses, randomizes again and could > show duplicate fields and not at all show other fields. > > Does anyone know a way round this? > > -- > Regards, > Georgie Casey > [EMAIL PROTECTED] > > *** > http://www.filmfind.tv > Ireland's Online Film Production Directory > *** > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Random Selecting from mySQL
are you just looking for a way to display 10 results per page? If yes then you can just use LIMIT to limit your result to 10 .. So, for the first page, you can do "SELECT LIMIT 1, 10;" and for the second page "SELECT ... LIMIT 11, 20" etc etc . You can sure use "ORDER BY" with "LIMIT" to to sort the results for a given criteria .. Gurhan -Original Message- From: Georgie Casey [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 13, 2002 2:00 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP-DB] Random Selecting from mySQL I know how to use the "ORDER BY rand()" command on the end of queries to randomize selection, but that's no good when you want to only display 10 results per page. The next page the user chooses, randomizes again and could show duplicate fields and not at all show other fields. Does anyone know a way round this? -- Regards, Georgie Casey [EMAIL PROTECTED] *** http://www.filmfind.tv Ireland's Online Film Production Directory *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Random Selecting from mySQL
I know how to use the "ORDER BY rand()" command on the end of queries to randomize selection, but that's no good when you want to only display 10 results per page. The next page the user chooses, randomizes again and could show duplicate fields and not at all show other fields. Does anyone know a way round this? -- Regards, Georgie Casey [EMAIL PROTECTED] *** http://www.filmfind.tv Ireland's Online Film Production Directory *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php