Code:
<pre>
<?php
$links = array(
"arrayitem1",
"arrayitem2",
"arrayitem3",
"arrayitem4",
"arrayitem5",
"arrayitem6",
"arrayitem7",
"arrayitem8",
"arrayitem9",
"arrayitem10",
"arrayitem11"
);
$randomized_links=array_rand($links,3);
print_r($randomized_links);
foreach ($randomized_links as $linknumber) {
print $links[$linknumber] . "\n";
}
shuffle($links);
print_r(array_slice($links,0,4));
?>
Something like that might get you started. array_rand has a parameter that allows you to choose the number of array keys to return. It will make sure it reports no duplicates and remember, arrays start with an index of 0. If you intend to display the entire array, and don't really care about the keys, you can also use shuffle. shuffle combined with array_slice might be a little faster. Remember that shuffle alters your existing array -- if you need to reference it later in the original order, make a copy before you shuffle it.
With SQL (and I really hate when this is done on a live site) you can do something like:
Code:
select linkname,linkurl from tablename where category='teen' order by rand() limit 10;