Update a product's shopping cart from a product

0

Colleagues

I'm bringing in a shopping cart, the traditional way. See:

ButI'dliketoupdatetheproductswithoutbringingthemintoaloop.I'mdoingitthisway:

while($jmCarrinho=mysqli_fetch_object($sqlCarrinho)){......$mostrar.="<td><div align='center' style='margin-top: 25px'><input type='number' name='Quantidade[]' min='1' max='".$jmProdutos->Estoque."' value='".$jmCarrinho->QtdProdutos."' maxlength='3'></div></td>";

}

And picking up quantity updates this way:

<?php
foreach($_POST["Quantidade"] as $qtd){
 // Aqui crio o update
}

When I do this, I end up giving 03 updates or more depending on the amount of products in the cart. Can you just pick up this specific product from the specific product? For example. I would like to change the second product from 7 to 10 and only it to be updated.

    
asked by anonymous 28.03.2017 / 18:56

1 answer

0

It's not clear how the data is structured, but I assume it's in a database.

If I understand what you need to do, you will need JavaScript to help with this task. With JavaScript identify the fields that have changed and send only such fields. On the server side (PHP), you can even continue as you are already doing. Larger work would only be on the client side.

One suggestion is to load the page, a JavaScript script would store the initial values. Each time a field is edited, compare the new value with the initial value. If it is different, save a reference to this field.

When the user submits, iterates the data by generating an "on-the-fly" form and submits the form. Using JQuery can be more practical.

Since you have not posted any relevant code, I can not post a minimal example. You'll have to understand the logic above.

    
28.03.2017 / 19:17