Ci-après le code :
<?php

$query = "SELECT ownerID,ownername,ownerbureau, is_deleted FROM notes.owner WHERE is_deleted = 0 AND ownername IS NOT NULL  ORDER BY     ownername,ownerbureau";
     //  Prépare une requête à l'exécution et retourne un objet
    $stmt = $pdo->prepare($query);
    // Exécute une requête préparée
    $stmt->execute();

    $previousGroup ="";
    $first_group   = true;

    ?>
    <select id="IDowner" name="IDowner[]" class="mdb-select colorful-select dropdown-primary md-form" multiple="multiple" searchable="Rechercher .." required="required" tabindex="2">
<?php while($b = $stmt->fetch(PDO::FETCH_ASSOC)){
        if ($b['ownername'] != $previousGroup){
            if(!$first_group){
                echo '</optgroup>';
            }else{
                $first_group = false;
            }
            echo '<optgroup label ="'.$b['ownername'].'">';
            $previousGroup = $b['ownername'];
        }
    ?>
        <option value="<?php echo $b['ownerID'] ?>"
            <?php
            $array =  explode(',',$IDowner_note);
            foreach ($array as $item) {
                if (!(strcmp($b['ownerID'],$item))) {echo 'selected';}} ?>><?php echo $b['ownerbureau'] ?></option>
        <?php
      $sel_owner="";
    }
    echo '</optgroup>';
    ?>

</select>

Je récupère les bonnes valeurs, mais l'affichage est incorrect. Le problème se situe certainement au niveau de ces lignes

if ($b['ownername'] != $previousGroup){
    if(!$first_group){
        echo '</optgroup>';
    }else{
        $first_group = false;
    }
        echo '<optgroup label ="'.$b['ownername'].'">';
        $previousGroup = $b['ownername'];
                                                    }

mais je ne vois pas le problème. Merci

So sorry, but this is an English language community and so I don't understand what you're asking. How can I help?

I solved my problem. Thank you

OK, sorry I wasn't able to help. I'm really good with PHP if you need help again in the future.

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.