Sumar en tie4mpo real con javascrip y php
Publicado por Rodrigo (1 intervención) el 31/03/2015 15:47:25
Hola amigos, tengo un problema con las sumas en tiempo real con php, si alguien me puede ayudar le estare muy agradecido, tengo este codigo en javascript y html y funciona bien:
pero al querer enlazarla con mi tabla de una base de datos no rescata los valores y peor aun no hace la suma en tiempo real, alguein me puede dar una manito porfavoooorrrrr..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function calculo(cantidad,precio,inputtext,totaltext)
{
gndtotal= totaltext.value-inputtext.value;
// Calculo del subtotal
subtotal = precio*cantidad;
inputtext.value=subtotal;
//Calculo del total
total = eval(gndtotal);
totaltext.value = total + subtotal;
}
<form>
<table width="393" border="1">
<tr>
<td width="88">Producto</td>
<td width="74">Cantidad</td>
<td width="64">Precio/Ud</td>
<td width="139">Sub-Total</td>
</tr>
<?php
$conn = mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("miBD",$conn);
$sql = "select * from producto";
$query = mysql_query($sql,$conn);
while ($rows = mysql_fetch_array($query))
{
$precio = $rows["precioventalm"];
$nombre = $rows["nombreprod"];
echo '<tr>';
echo '<td width=88>'.$nombre.'</td>';
echo '<td><input type=text size=3 id='.$nombre.' value=0 onChange=calculo(this.value,precio'.$nombre.'.value,subtotal'.$nombre.',total);></td>';
echo '<td><input type=hidden id=precio'.$nombre.' value='.$precio.'/>'.$precio.'</td>';
echo '<td><input type=text size=8 id=subtotal'.$nombre.' value=0>Bs.</td>';
echo '</tr>';
}
?>
<--
<tr>
<td>Platanos</td>
<td><input type="text" size="3" id="platanos" value="0" onChange="calculo(this.value,precio_platanos.value,subtotalplatanos,total);">uds</td>
<td><input type="hidden" id="precio_platanos" value="10"/> 10€</td>
<td><input type="text" size="8" id="subtotalplatanos" value="0">€</td>
</tr>
<tr>
<td>Manzanas</td>
<td><input type="text" size="3" id="manzanas" value="0" onChange="calculo(this.value,precio_manzanas.value,subtotalmanzanas,total);">uds</td>
<td><input type="hidden" id="precio_manzanas" value="3"/>3€</td>
<td><input type="text" size="8" id="subtotalmanzanas" value="0">€</td>
</tr>
-->
<tr>
<td colspan="3"><div align="right">Total:</div></td>
<td><input type="text" id="total" size="8" value="0">Bs.</td>
</tr>
</table>
</form>
pero al querer enlazarla con mi tabla de una base de datos no rescata los valores y peor aun no hace la suma en tiempo real, alguein me puede dar una manito porfavoooorrrrr..
Valora esta pregunta


0