How to associate values (price) passed through the mysqli_fetch_array to a product?

Asked

Viewed 58 times

1

I wonder how to associate some values I have stored in a array is a specific product, follows below my code:

<?php while ($consulta = $result->fetch_array()) { ?>
    <!--laço para dispor produtos no card-->
    <div class="col-md-4">
        </br>
        <figure class="card card-product">
            <div class="img-wrap"><?php echo "<img src='../image/" . $consulta['image'] . "' />" ?></div>
            <figcaption class="info-wrap">
                <h4 class="title"><?php echo $consulta['nome'] ?></h4>
                <p class="desc"><?php echo utf8_encode($consulta["observacao"]) ?></p>
            </figcaption>

            <div class="bottom-wrap">

                <?php $valor = $consulta["valor"] ?>
                <?php if ($saldo >= $consulta["valor"]) { ?>
                    <!--Condicional para realizar pedido-->

                    <button type="button" class="btn btn-success float-right" data-toggle="modal" data-target="#modalProduto">
                        Solicitar
                    </button>

                    <!-- Modal -->
                    <div class="modal fade" id="modalProduto" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="ModalLabel">Confirmação de compra</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body modalzin">
                                    <img src="../src/img/customer-service.png" alt="customer-service">
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                                    <button type="button" id="adq" class="btn btn-success conf">Confirmar</button>
                                </div>
                            </div>
                        </div>
                    </div>

                <?php } else { ?>
                    <button type="button" class="btn btn-danger float-right" disabled>
                        Saldo insuficiente
                    </button>
                <?php } ?>

                <div class="price-wrap h5">
                    <span class="price-new" id="price-new"><?php echo $consulta["valor"] ?></span>
                </div> <!-- price-wrap.// -->

            </div> <!-- bottom-wrap.// -->
        </figure>
    </div> <!-- col // -->
<?php } ?><!--laço para dispor produtos no card.//-->

In the code above you have a $consulta['valor'] which stores the values I have in the DB, all this tie disposes each product in one card, the question is:

How can I do so when the customer clicks the button solicitar, he takes only the value that’s in that card specific and not the vector $consulta['valor'] inteiro?

  • I believe that one way would be to play the value in the "value" property of an input and then pick it up via POST when clicking on Ubmit

  • vc can use a foreach of the value array to associate to the desired record;

  • I managed to solve this question, I put an attribute data-valor="<?= $consulta['valor'] ?>" request button and used a jquery function <script> $(".pegValor"). on('click', Function() { Let element; element = $(this).data('value'); console.log(element); }); </script>`

  • Thanks for the suggestions :)

No answers

Browser other questions tagged

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