Re: [PHP] Random SELECT SQL list

2007-05-20 Thread Eduardo Vizcarra
Hi Larry,Paul,Zoltán

Thanks for your messages, adding ORDER BY RAND () worked just fine

:)
Eduardo
Larry Garfield [EMAIL PROTECTED] escribió en el mensaje 
news:[EMAIL PROTECTED]
 On Wednesday 16 May 2007, Eduardo Vizcarra wrote:
 Hi

 I would like to know if a SELECT SQL query list of records can be 
 unsorted.
 SELECT statement retrieves a list of records from a certain table 
 starting
 from record # 1 till record #N and when publishing the records, this is 
 how
 it is presented, in a sequential way, is there any way to not present 
 them
 in a sequential way ? e.g. if a user accesses a web page then he will see
 record #3 and then #7 and so on, another user accesses the same web page
 and he might see record #8 and then record#2. etc

 any experience on how to do this ?

 This is really an SQL question, but it's quite easy.  Assuming MySQL:

 $result = mysql_query(SELECT * FROM foo WHERE bar='baz' ORDER BY 
 RAND());
 // Do stuff here.

 -- 
 Larry Garfield AIM: LOLG42
 [EMAIL PROTECTED] ICQ: 6817012

 If nature has made any one thing less susceptible than all others of
 exclusive property, it is the action of the thinking power called an idea,
 which an individual may exclusively possess as long as he keeps it to
 himself; but the moment it is divulged, it forces itself into the 
 possession
 of every one, and the receiver cannot dispossess himself of it.  --  
 Thomas
 Jefferson 

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



Re: [PHP] Random SELECT SQL list

2007-05-17 Thread Zoltán Németh


2007. 05. 17, csütörtök keltezéssel 00.45-kor Larry Garfield ezt írta:
 On Wednesday 16 May 2007, Eduardo Vizcarra wrote:
  Hi
 
  I would like to know if a SELECT SQL query list of records can be unsorted.
  SELECT statement retrieves a list of records from a certain table starting
  from record # 1 till record #N and when publishing the records, this is how
  it is presented, in a sequential way, is there any way to not present them
  in a sequential way ? e.g. if a user accesses a web page then he will see
  record #3 and then #7 and so on, another user accesses the same web page
  and he might see record #8 and then record#2. etc
 
  any experience on how to do this ?
 
 This is really an SQL question, but it's quite easy.  Assuming MySQL:
 
 $result = mysql_query(SELECT * FROM foo WHERE bar='baz' ORDER BY RAND());
 // Do stuff here.

ORDER BY RAND can be very unefficient on large tables.
some useful info here:
http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/

greets
Zoltán Németh

 
 -- 
 Larry GarfieldAIM: LOLG42
 [EMAIL PROTECTED] ICQ: 6817012
 
 If nature has made any one thing less susceptible than all others of 
 exclusive property, it is the action of the thinking power called an idea, 
 which an individual may exclusively possess as long as he keeps it to 
 himself; but the moment it is divulged, it forces itself into the possession 
 of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
 Jefferson
 

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



[PHP] Random SELECT SQL list

2007-05-16 Thread Eduardo Vizcarra
Hi

I would like to know if a SELECT SQL query list of records can be unsorted. 
SELECT statement retrieves a list of records from a certain table starting 
from record # 1 till record #N and when publishing the records, this is how 
it is presented, in a sequential way, is there any way to not present them 
in a sequential way ? e.g. if a user accesses a web page then he will see 
record #3 and then #7 and so on, another user accesses the same web page and 
he might see record #8 and then record#2. etc

any experience on how to do this ?

Regards
Eduardo 

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



Re: [PHP] Random SELECT SQL list

2007-05-16 Thread Paul Novitski

At 5/16/2007 09:40 PM, Eduardo Vizcarra wrote:

I would like to know if a SELECT SQL query list of records can be unsorted.
SELECT statement retrieves a list of records from a certain table starting
from record # 1 till record #N and when publishing the records, this is how
it is presented, in a sequential way, is there any way to not present them
in a sequential way ? e.g. if a user accesses a web page then he will see
record #3 and then #7 and so on, another user accesses the same web page and
he might see record #8 and then record#2. etc



Found on this page:
http://dev.mysql.com/doc/refman/5.1/en/select.html

Posted by Boris Aranovich on June 9 2004 2:33pm

I am using this way to select random row or rows:

SELECT * [or any needed fileds], idx*0+RAND() as rnd_id FROM 
tablename ORDER BY rnd_id LIMIT 1 [or the number of rows]


Meanwhile, I didn't stumble in any problems with this usage.
I picked this method in some forum, don't remember when, where or by 
who was it introduced :)



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



Re: [PHP] Random SELECT SQL list

2007-05-16 Thread Larry Garfield
On Wednesday 16 May 2007, Eduardo Vizcarra wrote:
 Hi

 I would like to know if a SELECT SQL query list of records can be unsorted.
 SELECT statement retrieves a list of records from a certain table starting
 from record # 1 till record #N and when publishing the records, this is how
 it is presented, in a sequential way, is there any way to not present them
 in a sequential way ? e.g. if a user accesses a web page then he will see
 record #3 and then #7 and so on, another user accesses the same web page
 and he might see record #8 and then record#2. etc

 any experience on how to do this ?

This is really an SQL question, but it's quite easy.  Assuming MySQL:

$result = mysql_query(SELECT * FROM foo WHERE bar='baz' ORDER BY RAND());
// Do stuff here.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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