$positions = array();
for ($i = 0; $i < $n; $i++) {
$pick = rand(0, $cant - 1);
if (!in_array($pick, $positions))
$positions[] = $pick;
}
// Now that we have the positions we just build the data
$ret = array();
$temp_max = count($positions);
for ($i = 0; $i < $temp_max; $i++) {
$index = $positions[$i];
$query = "select `blogId` from `tiki_blogs`";
$name = $this->getOne($query,array(),1,$index);
$ret[] = $name;
}
return $ret;
}
Hi there, I think your problem lies in the manipulation of your arrays.
Look at the code of the positions array you create. Usiing an iteration
is good idea, so why don't you use the $i to set the key of the $positions array.
What I mean is, you should do it like this:
[php]
$positions=array()
for ($i = 0; $i < $n; $i++)
{
$pick = rand(0, $cant - 1);
if (!in_array($pick, $positions))
{
$positions[$i] = $pick;
}
}
[/php] The second pard of the script has alsmost the same problem.
Your $ret variable is an array. In order to print out every
elelment of the array you should use some kind of cycle to go
through the array.
In order to display the $ret data, you should do something like:
[php]
...
foreach($ret as $result)
{
return $result;
}
[/php]
Try fixing these, and advise outcome. Note that if $ret is an array,
composed of arrays, you should cycle the arrays contained as well.
Hope it will work.