Actualizar campo automaticamente
Publicado por racingman (14 intervenciones) el 10/10/2012 08:42:19
Buenos días,
Tengo el siguiente codigo con un listado de participantes donde introduzco el tiempo de salida y el de meta y quiero que al introducir o modificar cualquiera de los valores, calcule automaticamente la diferencia entre los dos.
index.php
Lo cuestion seria, al guardar los registros TSalidaT14 y TMetaT14 calcule automaticamente la diferencia, que lo guarde en MiliSegT14 y que lo muestre. El tiempo de salida y meta lo introduzco mediante JEditable.
save.php
Gracias
Tengo el siguiente codigo con un listado de participantes donde introduzco el tiempo de salida y el de meta y quiero que al introducir o modificar cualquiera de los valores, calcule automaticamente la diferencia entre los dos.
index.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
//inicio de sesion
session_start();
//control de la sesion
if (!isset($_SESSION["controlcr"])) {
$_SESSION["IDCarreracr"] = $_GET["idrcr"];
$_SESSION["IDTramocr"] = $_GET["idtrcr"];
$_SESSION["controlcr"] = TRUE;
}
if (($_SESSION["controlcr"])==TRUE):
// incluimos la conexión
include("../../conexion.php");
// creamos la consulta
mysql_query("SET NAMES 'utf8'");
//$query ="SELECT * FROM ............";
// enviamos la consulta a MySQL
$queEmp = mysql_query($query, $conexion);
$resEmp = mysql_fetch_array($queEmp);
require('../header.php');
?>
<script type="text/javascript" src="query-1.8.0.min.js"></script>
<script type="text/javascript" src="jquery.jeditable.js"></script>
<script type="text/javascript" src="jeditable.js"></script>
<fieldset id="content">
<!--<legend>Editando registros de una tabla con Jeditable plugin jQuery.</legend>-->
<legend><?php echo $resEmp['NombreCarreraT01'];?></legend>
<table width="940" id="mytable" cellspacing="0">
<thead>
<tr class="head">
<th scope="col" width="20">Nº</th>
<th scope="col" width="200">PILOTO</th>
<th scope="col" width="200">COPILOTO</th>
<th scope="col" width="200">VEHICULO</th>
<th scope="col" width="25">CL.</th>
<th scope="col" width="25">GR.</th>
<th scope="col" width="90">SALIDA</th>
<th scope="col" width="90">META</th>
<th scope="col" width="90">DIFERENCIA</th>
</tr>
</thead>
<tbody>
<?php
//volver al primer registro
mysql_data_seek ( $queEmp, 0);
while($resEmp = mysql_fetch_array($queEmp)) {
$id = $resEmp['IDParticipanteT02'];
?>
<tr>
<th scope="row" class="spec"><?php echo $resEmp['DorsalT02'];?></th>
<td><?php echo $resEmp['PilotoT02'];?></th>
<td><?php echo $resEmp['CopilotoT02'];?></th>
<td><?php echo $resEmp['VehiculoT02'];?></th>
<td align="center"><?php echo $resEmp['NombreT08'];?></th>
<td align="center"><?php echo $resEmp['NombreT07'];?></th>
<?php
$query2 = "SELECT * FROM T14Tiempos WHERE (((T14Tiempos.IDCarreraT14)=". $_SESSION['IDCarreracr'] .") AND ((T14Tiempos.IDTramoT14)=". $_SESSION['IDTramocr'] .") AND ((T14Tiempos.IDParticipanteT14)='".$id."'))";
$queEmp2 = mysql_query($query2, $conexion);
$resEmp2 = mysql_fetch_array($queEmp2);
?>
<td><div class="text" id="TSalidaT14-<?php echo $id ?>"><?php echo $resEmp2['TSalidaT14']?></div></td>
<td><div class="text" id="TMetaT14-<?php echo $id ?>"><?php echo $resEmp2['TMetaT14']?></div></td>
<td><?php echo $resEmp2['MiliSegT14'];?></th>
</tr>
<?php }//endforeach; ?>
</tbody>
</table>
</fieldset>
<?php
endif;
?>
Lo cuestion seria, al guardar los registros TSalidaT14 y TMetaT14 calcule automaticamente la diferencia, que lo guarde en MiliSegT14 y que lo muestre. El tiempo de salida y meta lo introduzco mediante JEditable.
save.php
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
<?php
//inicio de sesion
session_start();
include("../../conexion.php");
$data = explode("-",$_POST['id']);
$campo = $data[0]; // nombre del campo
$id = $data[1]; // id del registro
$value = $_POST['value']; // valor por el cual reemplazar
$IDCarreracr = $_SESSION["IDCarreracr"];
$IDTramocr = $_SESSION["IDTramocr"];
// sql para actualizar el registro
mysql_query("SET NAMES 'utf8'");
$sql = "SELECT * FROM T14Tiempos WHERE (((T14Tiempos.IDCarreraT14)='$IDCarreracr') AND ((T14Tiempos.IDTramoT14)='$IDTramocr') AND ((T14Tiempos.IDParticipanteT14)= '$id'))";
$queTmp = mysql_query($sql, $conexion);
$total = mysql_num_rows($queTmp);
//echo "$total Total\n $IDCarreracr Carrera\n $IDTramocr Tramo\n";
if ($total>0) {
mysql_query("SET NAMES 'utf8'");
$actualizar = mysql_query("UPDATE T14Tiempos SET ".$campo." = '".$value."' WHERE IDParticipanteT14 = '".$id."'");
}
else {
mysql_query("SET NAMES 'utf8'");
$insertar = "INSERT INTO T14Tiempos (IDCarreraT14, IDTramoT14, IDParticipanteT14, ".$campo.") ";
$insertar.= "VALUES ('".$IDCarreracr."', '".$IDTramocr."', '".$id."', '".$value."')";
mysql_query($insertar, $conexion);
}
echo $value;
?>
Gracias
Valora esta pregunta


0