
almacenar valores en un Array que esta dentro de un bucle
Publicado por Array (36 intervenciones) el 25/10/2013 16:42:36
Buen dia
Lo que pasa es que necesito almacenar una variable en un array php, pero el problema es que esta variable esta dentro de un ciclo while de php , entonces la variable tiene varios resultados pero tiene el mismo nombre para todos los resultados ¿como ago para que todos los resultados me queden en un array?
El codigo que tengo es el siguiente y la variable que necesito guardar en el array se llama $general_profe:
Lo que pasa es que necesito almacenar una variable en un array php, pero el problema es que esta variable esta dentro de un ciclo while de php , entonces la variable tiene varios resultados pero tiene el mismo nombre para todos los resultados ¿como ago para que todos los resultados me queden en un array?
El codigo que tengo es el siguiente y la variable que necesito guardar en el array se llama $general_profe:
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
$id=mysql_query("select distinct id_profesor from respuestas_preguntas_profe where semestre='$semestre'",$conexion) or die (mysql_error());
while ($sede=mysql_fetch_array($id)){
$gen_pro=0;
$por=0;
$id_profesor=$sede['id_profesor'];
echo "<br>";
echo "<br>";
echo "<table class='table-bordered' align='center' border=>";
echo "<tr><td colspan='2' align='center'>";
$n_pr=mysql_query("select nombre from formulario where id_usuario='$id_profesor'",$conexion) or die (mysql_error());
$n_pro=mysql_fetch_array($n_pr);
$nombre_profesor=$n_pro['nombre'];
$nom_profe_may=strtoupper($nombre_profesor);
echo "<b><i>PROFESOR $nom_profe_may</i></b>";
echo "</td></tr>";
$se=mysql_query("select distinct id_titulo_profe from respuestas_preguntas_profe",$conexion) or die (mysql_error());
while ($sed=mysql_fetch_array($se)){
$tu=0;
$vec=0;
$id_titulo_profe=$sed['id_titulo_profe'];
$nom_t=mysql_query("select titulo_profe from titulos_autoevaluacion_profe where id_titulo_profe='$id_titulo_profe'",$conexion) or die (mysql_error());
$nom_ti=mysql_fetch_array($nom_t);
$titulo_profe=$nom_ti['titulo_profe'];
echo "<tr><td> </td></tr>";
echo "<tr><td colspan='2' align='center'>";
echo "<b><i>$titulo_profe</i></b>";
echo "</td></tr>";
echo "<tr><td>";
echo "<b>Preguntas</b>";
echo "</td>";
echo "<td>";
echo "<b>Promedio pregunta</b>";
echo "</td></tr>";
$id_p=mysql_query("select distinct id_pregunta_profe from respuestas_preguntas_profe where id_titulo_profe='$id_titulo_profe'",$conexion) or die (mysql_error());
while ($id_pr=mysql_fetch_array($id_p)){
$id_pregunta_profe=$id_pr['id_pregunta_profe'];
$b=0;
$nom_p=mysql_query("select pregunta_profe from preguntas_profe where id_pregunta_profe='$id_pregunta_profe'",$conexion) or die (mysql_error());
$nom_pr=mysql_fetch_array($nom_p);
$pregunta_profe=$nom_pr['pregunta_profe'];
$sql="SELECT COUNT(*) as total FROM respuestas_preguntas_profe where id_titulo_profe='$id_titulo_profe' and id_pregunta_profe='$id_pregunta_profe' and id_profesor='$id_profesor' and semestre='$semestre'";
$resultado=mysql_query($sql) or die ("no da" .mysql_error());
$total_profe=mysql_result($resultado,0,"total");
$pors=mysql_query("select porcentaje_profe from respuestas_preguntas_profe where id_titulo_profe='$id_titulo_profe' and id_pregunta_profe='$id_pregunta_profe' and id_profesor='$id_profesor' and semestre='$semestre'",$conexion) or die (mysql_error());
while ($porse=mysql_fetch_array($pors)){
$porcentaje_profe=$porse['porcentaje_profe'];
$b=$porcentaje_profe+$b;
$porcentaje_pregunta_profe=$b/$total_profe;
$porcentaje_pregunta_profe_jo=round($porcentaje_pregunta_profe * 100) / 100;
}
echo "<tr><td>";
echo "$pregunta_profe";
echo "</td>";
echo "<td align='center'>$porcentaje_pregunta_profe_jo %</td>";
echo "</tr>";
$vec=$vec+1;
$tu=$porcentaje_pregunta_profe+$tu;
$porcen_titulo_pro=$tu/$vec;
$porcentaje_titulos_profe=round($porcen_titulo_pro * 100) / 100;
}
echo "<tr><td> </td></tr>";
echo "<tr><td>";
echo "<b><font color='#076FB5'>Promedio $titulo_profe</font></b>";
echo "</td><td align='center'><font color='#076FB5'><b>$porcentaje_titulos_profe %</b></font></td></tr>";
$por=$por+1;
$gen_pro=$porcentaje_titulos_profe+$gen_pro;
$gene_profe=$gen_pro/$por;
$general_profe=round($gene_profe * 100) / 100;
}
echo "<tr><td> </td></tr>";
echo "<tr><td>";
echo "<b><font color='#520914'>Promedio $nombre_profesor</font></b>";
echo "</td><td align='center'><font color='#520914'><b>$general_profe %</b></font></td></tr>";
$profe=$profe+1;
echo "</table>";
}
Valora esta pregunta


0