Good morning I'm doing the insertion of orders and I need some help. The idea is that according to two selects the result has to come out in an input.
On the one hand we have the producto
that is in the table productos
+----+----------+--------+
| id | producto | estado |
+----+----------+--------+
| | | |
| | | |
+----+----------+--------+
The product selection
<select id="select2-2" value="" class="form-control" name="select2-2">
<option value="0">Seleciona un producto</option>
<?php
$resultisa = $mysqli->query("SELECT *
FROM productos WHERE estado = 1");
mysqli_set_charset("utf8");
while($resia = $resultisa->fetch_array()) {
?>
<option value="<?php echo $resia['id'] ?>"><?php echo $resia['producto'] ?> <?php echo $resia['alias'] ?></option>
<?php } ?>
</select>
On the other hand we have the tipo de contrato
that is in the table tipos
+----+----------+--------+
| id | tipo | estado |
+----+----------+--------+
| | | |
| | | |
+----+----------+--------+
The selection of contract types
<select id="select2-4" value="" class="form-control" name="select2-4">
<option value="0">Tipo contrato</option>
<?php
$resultisa = $mysqli->query("SELECT *
FROM tipos WHERE estado = 1");
mysqli_set_charset("utf8");
while($resia = $resultisa->fetch_array()) {
?>
<option value="<?php echo $resia['id'] ?>"><?php echo $resia['tipo'] ?></option>
<?php } ?>
</select>
Then we have the table, that depending on what you choose, you have to leave the input in% input Tabla posibles
:
+----+----------+--------+---------+-------------+---------+
| id |idproducto| tipo | entrada | mensualidad | final |
+----+----------+--------+---------+-------------+---------+
| | | | | | |
| | | | | | |
+----+----------+--------+---------+-------------+---------+
Here the Select for the possible table:
<select id="select2-4" value="" class="form-control" name="select2-4">
<option value="0">Selecciona</option>
<option value="1">Entrada</option>
<option value="2">Mensualidad</option>
<option value="3">Cuota Final</option>
</select>
And here the input where to show the result:
<input type="text" class="form-control inputmiocont corpiii" id="eTotal" name="eTotal">
The idea that if they choose:
First select the id:1
that is Láser de diodo
Second Select: id:2
which is comprar
Third Select: Value="1"
that is Entry
In the input they have to leave: 13225
What you have to do is compare why sometimes the field will be empty since that possibility does not exist.
----------------- POSSIBILITIES ---------------------
Table productos
+----+-----------+--------+
| id | producto | estado |
+----+-----------+--------+
| 1 |LASER DIODO| 1 |
| 2 | DUALWAVE | 1 |
+----+-----------+--------+
Table tipos
+----+------------+--------+
| id | tipo | estado |
+----+------------+--------+
| 1 | ALQUILER | 1 |
| 2 | COMPRAR | 1 |
| 3 | EXPLOTACION| 1 |
| 4 | ALQ.COMPRA | 1 |
+----+------------+--------+
Tabla posibles
: I put it in two types of products, but there are more
+----+----------+--------+---------+-------------+---------+
| id |idproducto| tipo | entrada | mensualidad | final |
+----+----------+--------+---------+-------------+---------+
| 1 | 2 | 1 | 0 | 455 | 0 |
| 2 | 2 | 2 | 13225 | 0 | 0 |
| 3 | 2 | 3 | 0 | 0 | 0 |
| 4 | 2 | 5 | 1900 | 385 | 500 |
| 5 | 1 | 1 | 0 | 435 | 0 |
| 6 | 1 | 2 | 12900 | 0 | 0 |
+----+----------+--------+---------+-------------+---------+
The third selection let's say it's for the ultimate filter, if it's input, menuality or final.
Let's make an example;
We chose the DUALWAVE product from the first selection
We chose from the second select RENT
And we chose in the third selection MENSUALIDAD
Result = 455.
If we had chosen in the third select, input will be = 0
I do not know if this is something clearer, I hope so, thank you!
EDITIONS
Valor del id del producto
<script>
$(document).ready(function(){
$("#select2-2").click(function(){
var valor= $("#select2-2").val();
});
});
</script>
Valor tipo contrato
<script>
$(document).ready(function(){
$("#select2-4").click(function(){
var valor= $("#select2-4").val();
});
});
</script>
Valor filtro
<script>
$(document).ready(function(){
$("#select2-3").click(function(){
var valor= $("#select2-3").val();
});
});
</script>
Sacar variables
<script>
var idProducto = $('#select2-2').val();
var idTipo = $('#select2-4').val();
var idFiltro = $('#select2-3').val();
</script>
Query
<?php $resultado = $mysqli->query("SELECT " . idFiltro . "FROM posibles WHERE idproducto = " . idProducto . " AND tipo = " .idTipo); ?>
imprimimos query
<input type="text" class="form-control inputmiocont corpiii" id="eTotal" name="eTotal" value="<?php echo $resultado;?>">