Re: Randomly select 5 records from a db

From: Date: Tue, 03 Oct 2000 00:22:21 +0000
Subject: Re: Randomly select 5 records from a db
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-18332@lists.php.net to get a copy of this message
Yes, you're doing something wrong. :-) Let's see the exact query. Copy and paste it here from your script. Maybe you forgot the order by clause.
Here it is... <? // connect to database here $sql = "SELECT *, 3*0+RAND() AS rand_col FROM meminfo WHERE type='bene' ORDER BY rand_col LIMIT 2"; $result= mysql_query($sql); while($myrow=mysql_fetch_array($result)) { print "$myrow[title]<BR>"; } mysql_close($db); ?>

« previous php.general (#18332) next »