Actualizar Múltiples Registros a la vez
Publicado por Jorge (2 intervenciones) el 16/01/2013 17:12:15
Quisiera que me ayudaran con la actualización de registros pero en forma múltiple, es decir que se pueda modificar todos los datos mostrados. En mi caso tengo las notas de los alumnos, y lo quiero es que un docente, pueda modificar todas las notas de una clase sin necesidad de ir seleccionando una a una. El código que he generado con Dreamweaver para actualizar UN SÓLO REGISTRO Y QUE SI FUNCIONA es el siguiente:
******************************************************
*****************************************************************
Por favor necesito su ayuda ...
******************************************************
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE notas SET lt1=%s, lt2=%s, lt3=%s, pf=%s WHERE nombre_alumno=%s AND curso=%s",
GetSQLValueString($_POST['lt1'], "text"),
GetSQLValueString($_POST['lt2'], "text"),
GetSQLValueString($_POST['lt3'], "text"),
GetSQLValueString($_POST['pf'], "text"),
GetSQLValueString($_POST['nombre_alumno'], "text"),
GetSQLValueString($_POST['curso'], "text"));
mysql_select_db($database_cNotas, $cNotas);
$Result1 = mysql_query($updateSQL, $cNotas) or die(mysql_error());
$updateGoTo = "doc_notas_mod2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_not = "-1";
if (isset($_GET['nombre_alumno'])) {
$colname_not = $_GET['nombre_alumno'];
}
$colcurso_not = "-1";
if (isset($_GET['curso'])) {
$colcurso_not = $_GET['curso'];
}
mysql_select_db($database_cNotas, $cNotas);
$query_not = sprintf("SELECT * FROM notas WHERE nombre_alumno = %s AND curso = %s", GetSQLValueString($colname_not, "text"),GetSQLValueString($colcurso_not, "text"));
$not = mysql_query($query_not, $cNotas) or die(mysql_error());
$row_not = mysql_fetch_assoc($not);
$totalRows_not = mysql_num_rows($not);
$colname_usu = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_usu = $_SESSION['MM_Username'];
}
mysql_select_db($database_cNotas, $cNotas);
$query_usu = sprintf("SELECT * FROM docentes WHERE usuario = %s", GetSQLValueString($colname_usu, "text"));
$usu = mysql_query($query_usu, $cNotas) or die(mysql_error());
$row_usu = mysql_fetch_assoc($usu);
$totalRows_usu = mysql_num_rows($usu);
mysql_select_db($database_cNotas, $cNotas);
$query_gru = "SELECT * FROM grupos WHERE nombre_docente = '$row_usu[nombre_docente]'";
$gru = mysql_query($query_gru, $cNotas) or die(mysql_error());
$row_gru = mysql_fetch_assoc($gru);
$totalRows_gru = mysql_num_rows($gru);
?>
*****************************************************************
Por favor necesito su ayuda ...
Valora esta pregunta
0