Only display members with a status in a select with php pdo

0

What I'm trying to do is select all members of the members table that have the name Lider in the "member" column display in the select sorted by name.

                                <div class="form-group">
                                <label for="selector1" class="col-sm-2 control-label">Líder</label>
                                <div class="col-sm-8">
                                    <select name="lider" id="lider" class="form-control1">
                                    <option value="SEM CÉLULA">SEM CÉLULA</option>
                                    <?php
                                    require_once("../cfg/base.php");
                                    $db=get_db();
                                    $stmt = $db-> prepare( 'SELECT membro, nome FROM membros WHERE membro = "Lider" ORDER BY nome' );
                                    $stmt-> execute();
                                    $result = $stmt-> fetchAll( PDO::FETCH_ASSOC );
                                    ?>
                                    <?php foreach( $result as $row ) { ?>
                                    <option value="<?php echo $row['nome'];?>"><?php echo $row['nome'];?></option>
                                     <?php } ?>

                                                                     

    
asked by anonymous 19.01.2018 / 10:01

1 answer

1

Add the index of the returned array as

<?php foreach( $result as $row ) { ?> <option value="<?php echo $row[0]['nome'];?>"><?php echo $row['nome'];?></option> <?php } ?>
    
19.01.2018 / 12:56