Hello, anyone can help me to add a background color to my div, for example, if an id of 2 is found (pls see my code)

$idMenuParent = $resGetInfoMenu[0]['IDMENUPARENT'];
        //if the menu has a parent
        if($idMenuParent) {
            // get menu info
            $infoMenuParent = cGetInfoMenu($idMenuParent);
            //fetch all child menus
            $secondMenus = cGetMenus($_SESSION['IDLANG'], 1, $idMenuParent);

            if(!empty($secondMenus)) {
                ?>
                <div id="secondary-menu-main">

                <div id="secondary-menu-items">              
                <?php
                foreach($secondMenus as $secondMenu) {
                    //get child menu info
                    $sousItem = cGetItemMenu($_SESSION['IDLANG'], $secondMenu['IDMENU']);
                    if($idMenuSelected == $secondMenu['IDMENU']) {
                        $selected = "-activated";
                    }
                    else {
                        $selected = "";
                    }

where i want to check the value of the variable $idMenuParent , and if it has for example value 2, to get the
div id="secondary-menu-items" background as blue in color, else any other value should return gray color.

Anyone can help me solve this issue?

Recommended Answers

All 3 Replies

I think it could be something like this:

if(!empty($secondMenus)) {

    $backgroundColor = $idMenuParent == 2 ? 'blue' : 'gray';

                ?>

                <div id="secondary-menu-main">

                <div id="secondary-menu-items" style="background-color: <?php echo $backgroundColor; ?> ">              
                <?php
                foreach($secondMenus as $secondMenu) {

we can add background color to div by using style property of div tag as shown bellow

<div id="your_id_value" style="background-color: grey">  
// you may give color name directly or its rgb value like (#FFCCEE)
</div>   

based on your condition you may add style property for the particular div tag

thats it

thanks, AleMonteiro's method is just what i needed

Be a part of the DaniWeb community

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