$test = $test -> GetList(array(array("Compliance_CourseId", "=",
$_POST["module_id"])),
"RAND()", true, "15");
But I just get the first 15 records. Help?
Thanks,
Aaron.
you're getting 15 records because the limit is 15, and passing rand()
as the field to sort by.
so, for instance, let's say rand() returns the value 1. getlist() will
try to sort by a field named "1". if there isn't such field, your list
will remain as-is and truncated to 15 items.
I don't really understand the purpose of Rand() in this case though..
maybe you can clarify this in another msg..
thanks
Joel
try using array_rand
(http://ca.php.net/manual/en/function.array-rand.php)
for instance,
srand((float) microtime() * 10000000);
$test = $test -> GetList(array(array("Compliance_CourseId", "=",
$_POST["module_id"])));
$rand_keys = array_rand($test, 15);
echo $test[$rand_keys[0]] . "\n";
echo $test[$rand_keys[1]] . "\n";
...
hope this helps
joel
For the kids back home, the complete solution looked a little
something like this:
$test = new Compliance_Tests();
$test = $test -> GetList(array(array("Compliance_CourseId", "=",
$_POST["module_id"])));
srand((float) microtime() * 10000000);
$rand_keys = array_rand($test, 15);
for($i=0; $i<15; $i++) {
echo $test[$rand_keys[$i]]->question;
}
Cheers!
Aaron.