I build a code to eventually get a random item per category. Functions are working. I am just curious if the WHILE and IF are accurate. I am not sure if the first two unset() is good or do I need to drop those? And more important WHY the random ALWAYS give me the same result first result as if $myitems holds only one???
<?php
// loop from array //
foreach ($mycats as $catvalue) {
// get my items //
query_item(array('category_name'=>$catvalue));
// check for items and has category name //
while ( has_items() && item_category()==$catvalue) {
// store items in array by title //
$myitems[] = item_title() ;
// make the array random //
$selected = array_rand(array_flip($myitems));
// request items again but with random title //
query_item(array('category_name'=>$catvalue));
while( has_items() && ( item_title()==$selected)){
// display my item //
draw_item($class);
}
// unset varible arrays but hold catvalue //
unset($myitems);
unset($selected);
}
}
// unset all variable arrays //
unset($myitems);
unset($selected);
unset($catvalue);
?>