Display day selection with php and pdo

0

On this page I'm making birthdays of the month, and I was able to display all the birthdays that I have in the current month, but I'm not able to display the day, which I also selected in the database ...

                   <?php
                            require 'cfg/db.php';

                             $conexao = conexao::getInstance();
                             $sql = 'SELECT id, nome, membro, foto, data_nascimento, DAY(data_nascimento) FROM membros WHERE DAY(data_nascimento) AND MONTH(data_nascimento)';
                             $stm = $conexao->prepare($sql);
                             $stm->execute();
                             $aniversariantes = $stm->fetchAll(PDO::FETCH_OBJ);
                             print_r($aniversariantes);
                      ?>

                      <?php 
            
            foreach($aniversariantes as $aniversariante):

                      ?>

                      <tr class="table-row">
                            <td class="table-img">
                              <img src='fotos/<?=$aniversariante->foto?>' height='40' width='40'>
                            </td>
                            <td class="table-text">
                              <h6><?=$aniversariante->nome?></h6>
                                <p><?=$aniversariante->membro?></p>
                            </td>

                            <td class="march">
                               Dia: 
                            </td>
                        </tr>
            <?php 

            endforeach;
            
            ?>
    
asked by anonymous 19.01.2018 / 17:13

1 answer

2

Change your select to:

SELECT id, nome, membro, foto, data_nascimento, DAY(data_nascimento) AS dia_nascimento FROM membros WHERE DAY(data_nascimento) AND MONTH(data_nascimento)

At the time of printing you do this:

<td class="march">
    Dia: <? echo $aniversariante->dia_nascimento; ?>
</td>

AS works as a nickname, so the column named DAY(data_nascimento) has been nicknamed as dia_nascimento .

    
19.01.2018 / 17:33