Display only members with a status in a <select> with php Pdo

Asked

Viewed 75 times

0

What I’m trying to do is select all members of the member table that have the Lider name in the "member" column display in 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 } ?>

  • OK but what is the problem that is giving?

  • Does not display in select the people who have Leader in the member column of the member table

  • but are returning from the bank?

  • I didn’t try to show it any other way and it’s not happening

  • From a print_r($result); and see if it shows something, tell me if it shows

  • Array ( [0] => Array ( [member] => Leader [name] => Leonardo ) )

  • ok here in this part do so <?php foreach( $result as $Row ) { ? > <option value="<? php echo $Row[0]['name'];? >"><? php echo $Row['name'];? ></option> <?php } ? > If it works please tell me to put as a thank you reply

  • It worked bro, thanks... put it there !

  • you could help me with one of my birthday kids?

  • I can, but how so?

  • is that I have no idea how to do...

  • gave error that last code :(

Show 8 more comments

1 answer

1


Add the index of the returned array like this

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.