How to make this condition work?

Asked

Viewed 58 times

-1

I need some help. What I’m trying to do is similar to the urban fish offerings, active while the time counter works and after the finish the information is replaced. but when use Lse does not work because the first condition remains true and if use one more if it adds the closed promotion information along with those of active promotion. How can I create this condition correctly? Note: I am beginner rs inserir a descrição da imagem aqui

  <?php 
        $sql = $pdo->prepare("SELECT * FROM estabelecimentos ORDER BY rand() LIMIT 4");
        $sql->execute();
        $portal = $sql->fetchAll();
  ?>


    <?php
            $currentDateTime = date('Y-m-d H:i:s');
            foreach($portal as $key => $value) {
                ?>

                <div class="col s12 m3">
                    <div class="card">
                        <div class="card-image">
                            <?php echo '<img src="data:image/jpg;base64,'.base64_encode( $value['imagem'] ).'"/>';  ?>
                        </div>
                        <div class="card-content">

                            <span class="card-title"><?php echo $value['nome']; ?></span>
                            <h5><?php echo $value['produto']; ?></h5>

                            <?php if($value['status'] == 'promo'){ ?>

                                        <div class="ticket"> 
                                           <span><img src="img/flame.png" alt=""></span>
                                         <span>Promoção turbinada</span>
                        </div>
                                           <p><span class="promo"><?php echo 'A partir de '.'R$'.$value['promo']. ',00'; ?></span></p>
                                        <div class="countdown" data-date="<?php echo $value['fimpromo']; ?>" data-time="<?php echo $value['datetime']; ?>"></div>

                            <?php } if ($value['fimpromo']<= $currentDateTime) {  ?>

                          <div class="ticket ticket-closed">
                             <span><img src="img/cancel.png" alt=""></span>
                             <span>Promoção Encerrada</span>
                          </div>

                            <?php } ?>
                        </div>
                    </div>
               </div>
                   <?php } ?>

1 answer

2


Try this way:

<section>
<div class="destaques">
     <div class="container">
        <h2 class="title center-align">Os Melhores Restaurantes!</h2>
        <p class="center-align">Do Rodízio ao à la carte, garanta já o seu:</p>
        <div class="row">       
            <?php $currentDateTime = date('Y-m-d H:i:s');  ?>

                <?php foreach($portal as $key => $value) :  ?>
            <div class="col s12 m3">
              <div class="card">
                <div class="card-image">
                  <?php echo '<img src="data:image/jpg;base64,'.base64_encode( $value['imagem'] ).'"/>';  ?>
                </div>
                <div class="card-content">
                  <span class="card-title"><?php echo $value['nome']; ?></span>
                  <h5><?php echo $value['produto']; ?></h5>
                  <?php if($value['status'] == 'promo'): ?>
                    <?php if ($value['fimpromo'] <= $currentDateTime) : ?>
                      <?php 
                        $sql2 = $pdo->prepare("UPDATE estabelecimentos SET status = :status WHERE id = :id");
                        $sql2->execute([':status' => 'closed', ':id' => $value['id']]);
                      ?>
                      <div class="ticket ticket-closed">
                        <span><img src="img/cancel.png" alt=""></span>
                        <span>Promoção Encerrada</span>
                      </div>
                    <?php else: ?>
                      <div class="ticket"> 
                        <span><img src="img/flame.png" alt=""></span>
                        <span>Promoção turbinada</span>
                      </div>                          
                      <div class="countdown" data-date="<?php echo $value['fimpromo']; ?>" data-time="<?php echo $value['datetime']; ?>"></div>
                    <?php endif; ?>
                    <p><span class="promo"><?php echo 'A partir de '.'R$'.$value['preco']. ',00'; ?></span></p>                        
                  <?php endif; ?>

                </div>
              </div>
            </div>
          <?php endforeach; ?>
       </div>
   </div>
</div>

Browser other questions tagged

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