jeudi 28 mai 2020

Problem with if statement and match with specific categories [duplicate]

I have a problem with an if statement

I want to display a different button for elements that are assigned to a specific category (7) than for elements that do not belong to that category:

<?php
            $result=get_media($ref);
            if(empty($result))

                include ('button1.php');

            if (count($result)>0)
            {

                for ($n = 0; $n < count($result); $n++)
                {

                    if($result[$n]["ref"] == '7')
                    {
                        include ('button2.php');
                    }
                    else 
                        include ('button1.php');
                }
            }
            ?>

The if statement works if the element is assigned to category "7" only. But if it is assigned to other categories as well, the "else" command is not working and both buttons are shown.

I could of course add more category IDs to the if statement but this would be a lot of them.

Also an unequal command in the else statement does not work.

Aucun commentaire:

Enregistrer un commentaire