RE: [PHP] random order by id

2002-05-18 Thread David Freeman


 > i have a db and a table with id and questions
 > now i want these questions to be listed in a random order, 
 > is there a way to format my SQL query or do i need some PHP 
 > work to?

It's best achieved in sql:

SELECT ID, Question FROM Questions WHERE Some = Condition ORDER BY
RAND() LIMIT 10

Will get you up to ten randomised questions based on your 'where'
condition.

CYA, Dave



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] random order by id

2002-05-18 Thread Richard Baskett

If you are using MySQL try looking at this page for the function rand():

http://www.mysql.com/doc/M/a/Mathematical_functions.html

Here's a little overview of what it says:

"In MySQL Version 3.23, you can, however, do: SELECT * FROM table_name ORDER
BY RAND() This is useful to get a random sample of a set SELECT * FROM
table1,table2 WHERE a=b AND c From: Jule <[EMAIL PROTECTED]>
> Date: Sat, 18 May 2002 17:41:59 -0400
> To: [EMAIL PROTECTED]
> Subject: [PHP] random order by id
> 
> 
> Hey guys,
> i have a db and a table with id and questions
> now i want these questions to be listed in a random order, is there a way
> to format my SQL query or do i need some PHP work to?
> i can ofcourse select a random one, that's no problem, but how do i make
> sure that that one does not get chosen again. and that after it has printed
> all the records it stops
> any ideas?
> 
> Jule
> 
> -- 
> |\/\__/\/|
> |   Jule Slootbeek |
> |   [EMAIL PROTECTED] |
> |   http://blindtheory.cjb.net |
> |   __ |
> |/\/  \/\|
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] random order by id

2002-05-18 Thread Jule


Hey guys,
i have a db and a table with id and questions
now i want these questions to be listed in a random order, is there a way
to format my SQL query or do i need some PHP work to?
i can ofcourse select a random one, that's no problem, but how do i make
sure that that one does not get chosen again. and that after it has printed
all the records it stops
any ideas?

Jule

-- 
|\/\__/\/|
|   Jule Slootbeek   |
|   [EMAIL PROTECTED]|
|   http://blindtheory.cjb.net   |
|   __   |
|/\/  \/\|

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php