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???


// loop from array //
foreach ($mycats as $catvalue) {

// get my items //

// 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 //
    while( has_items() && ( item_title()==$selected)){ 

        // display my item //

    // unset varible arrays but hold catvalue //

// unset all variable arrays //

Recommended Answers

Is this wordpress by any chance?

Jump to Post

All 3 Replies

Is this wordpress by any chance?

no wordpress

Member Avatar

Seems to be a lot of unnecessary code in the loop. I think. ALso you have loads of user-defined functions that could be causing errors - we have no way of knowing.

$class seems to be holding the variable that decides on the output, but nowhere is this set in your snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.