You could try this, it works fine :
<?php
$connection = mysql_connect ($host, $login, $password);
mysql_select_db ($DataBase, $connection) ;
$c = 5 ; // Whatever..
protected function randomselection($c, $connection) {
$data = getdata($connection) ; // Get your datas
somewhere you like to
$totalcount = count($data) ;
$j = array() ;
if ($c > $totalcount) { $newdata = $data ; } // if not
enough datas rows in $data
else {
for($i = 0; $i <= $c; $i++) {
$exists = 1 ;
for($exists > 0; $exists++;) {
$test = mt_rand(1,$totalcount) ; // depends on where
you want to start - can also use rand()
if(!in_array( $test , $j )) { $j[$i] = $test ; $exists
= 0 ; }
}
$newdata[$i] = $data[$j[$i]] ;
}
}
return $newdata ;
}
?>
----
Server IP: 194.246.101.61
Probable Submitter: 87.90.26.94
----
Manual Page -- http:/
/www.php.net/manual/en/function.rand.php
Edit -- https://master
.php.net/note/edit/70844
Del: integrated -- h
ttps://master.php.net/note/delete/70844/integrated
Del: useless -- http
s://master.php.net/note/delete/70844/useless
Del: bad code -- htt
ps://master.php.net/note/delete/70844/bad+code
Del: spam -- https:/
/master.php.net/note/delete/70844/spam
Del: non-english --
https://master.php.net/note/delete/70844/non-english
Del: in docs -- http
s://master.php.net/note/delete/70844/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/70844
Reject -- https://mast
er.php.net/note/reject/70844
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|