2
good evening I’m having a hard time performing a data recovery on I recover but wanted the recovery to be simultaneous I will explain better and once you see the code you will understand.
include("banco/banco.php");
$prod = $conexao_pdo->prepare(" SELECT *FROM precos ");
$prod->execute();
$result = $prod->fetchAll(PDO::FETCH_ASSOC);
recover the information of the bank with this querry, it returns to me the following information id_precos, name_precos, total_precos, which are related to the products.
<div class="col-sm-6">
<div class="form-group">
<div class="form-line">
<select name="produto" class="form-control show-tick">
<option value="">Produto</option>
<?php foreach($result as $prod){ ?>
<option value="<?php echo $prod['nome_precos']; ?>">
<?php echo $prod['nome_precos']; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<div class="formline">
<input type="text" class="form-control" value="" step="any" name="valor" readonly placeholder="Valor Unitario">
</div>
</div>
</div>
this code snippet retrieves the name of the products and place within a select for the user to choose I’m having difficulties in the following part when the user choose the name the value referring to the product name go to the unit value input.
<div class="col-sm-2">
<div class="form-group">
<div class="form-line">
<input type="number" class="form-control" name="quantidade" required placeholder="quantidade">
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<div class="form-line">
<input type="number" class="form-control" name="total" readonly required placeholder="total">
</div>
</div>
</div>
this above code the user enters the quantity of products he wishes to acquire would the product value la from above be multiplied by the quantity input that the user entered and return the total in the input. Who can give a cheer there I thank from now!
and how do I load the unit value question to the @dvd input
– Tulio Vieira
ah yes I’ve seen my mistake here made filet
– Tulio Vieira
at the end of to divide the total by a variable $_SESSION['discount']?
– Tulio Vieira
percentage if it has to add $ , 00 in the values that are going to the fields @dvd
– Tulio Vieira
@Tuliovieira Code updated. Just put a discount value in number format.
– Sam
only I need this value to be of the variable $_SESSION['discount']
– Tulio Vieira
blz to no aguardo @dvd
– Tulio Vieira
total stopped working
– Tulio Vieira
do not forget that I need the value of the discount comes from the variable $_SESSION['discount']
– Tulio Vieira
@Tuliovieira Change the total field to
type="text"
... and replace the discount line:var desconto = <?php if(empty($_SESSION['desconto'])){ echo '0';}else{ echo $_SESSION['desconto'];} ?>; // porcentagem de desconto
– Sam
was seeing here <option value="100">100</option> this taking the value of the product and not the name when I have inserted do not know the name of the product
– Tulio Vieira
@Tulip tree You have to change the value of options by name
– Sam
@Tuliovieira Perai who will need to adjust the code, I will update...
– Sam
@Tulip tree Just change that part:
var prod_preco = parseInt($("select[name='produto'] option:selected").text());
– Sam
if you make this change the stick code the inputs with the product price and the total do not work
– Tulio Vieira
@Tuliovieira Take a look and run the example in the answer. It works normal. The change I made did not influence anything as it was before. I just swapped the value selection for the select text.
– Sam
yes I understood but I did it the way it is there and nothing :/ if you want to pass the code snippet for you to see via Skype Whats.. @dvd
– Tulio Vieira
help ai @dvd not solved my problem
– Tulio Vieira
@Tulip tree There must be something else bugging the code. See in the example of the answer running the snippet, it works normal.
– Sam
only that the product is there as value and in my code the product has a name and a value the user clicks on the name and tals the imput receives the name of the product and not the value. in the querry I made it comes the name and the value tmb but n I can make it work
– Tulio Vieira
@Tuliovieira No select value is the name of the product and the text is the value. That’s not it?
– Sam
no value takes the product name and the text and the name tmb and the product value it do not know what to do to store and make the calculations @dvd
– Tulio Vieira
@Tulip tree I get it. That’s easy, I’ll update the answer and you take a look.
– Sam
@Tulip tree I created an attribute
data-valor
where I place value... value and text is the product name.– Sam
Top @dvd solved my problem
– Tulio Vieira