| 
 Posted by strawberry on 06/22/06 06:17 
in the query itself you could add 'order by rand() limit 4' 
 
vito wrote: 
> after executing the query, say it returns 1000 results. 
> 
> if i just want to do some sampling and like to have a look on 4 of them, 
> how can i refer to these 4 random records out of 1000? i'm working on 
> processing the result of $res_array which has 1000 records. 
> 
> query = select * from test; 
> 
> result = mysql_query(query); 
> 
> records1000 = db_result_to_array($result); 
> //how to select/remove records1000 to get say, records4? 
> 
> 
> function db_result_to_array($result) { 
>   $res_array = array(); 
>   for ($count=0; $row = $result->fetch_assoc(); $count++) { 
>   $res_array[$count] = $row; 
>   } 
>   return $res_array; 
> }
 
  
Navigation:
[Reply to this message] 
 |