Re: Selecting one row by random, where a column is set

From: Date: Sat, 20 Mar 2004 01:34:02 +0000
Subject: Re: Selecting one row by random, where a column is set
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-33568@lists.php.net to get a copy of this message
Mathias Hunskår Furevik wrote:
I've got the SQL line: $sql = "SELECT * FROM shop_items ORDER BY RAND() LIMIT 1"; I've got a column which is called image_large. The tricky part is, not all of the image_large rows exists. Whis the query above, I want to get only a row where image_large is present.
So add a WHERE clause... SELECT image_large FROM shop_items WHERE image_large != '' ORDER BY RAND() LIMIT 1 -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals - www.phparch.com

« previous php.db (#33568) next »