Foros del Web » Programando para Internet » PHP »

funcion PHP

Estas en el tema de funcion PHP en el foro de PHP en Foros del Web. Hola muy buenas, Bien les sitio, tengo 9 formularios en distintas ubicaciones de mi pagina web, i en todas ellas se pasan variables a una ...
  #1 (permalink)  
Antiguo 20/10/2010, 00:35
 
Fecha de Ingreso: octubre-2010
Mensajes: 1
Antigüedad: 13 años, 5 meses
Puntos: 0
funcion PHP

Hola muy buenas,

Bien les sitio, tengo 9 formularios en distintas ubicaciones de mi pagina web, i en todas ellas se pasan variables a una funcion PHP. Estas variables son notas de assignaturas, y su numero de creditos, y sus nombes en todos los formularios son los siguientes:

- notas = t1,t2,t3,t4,t5 ....tn
- creditos = c1,c2,c3,c4....cn

Puede haber de 1 a 12, segun el formuario desde el que se llame a la funcion PHP.

Para hacer la lectura de las variables y el calculo de la media, he hecho esta funcion PHP:

------------------
function calcula($num)
{
$assig = array();
$credits = array();
$notaTotal=0;
$creditsTotal=0;
$mis="hola";

for($a=0;$a < $num; $a++){
$assig[$a] = trim($_GET("t$a"));
$credits[$a] = trim($_GET("c$a"));
}

for($a=0;$a < $num; $a++){
$notaTotal = $notaTotal+ floatval($assig[$a]) * floatval($credits[$a]);
$creditsTotal = $creditsTotal + floatval($credits[$a]);
}

$notaTotal = floatval($notaTotal) / floatval($creditsTotal);
$cad1 = "Tu nota es ";
$cad2 = " : Aprovada";
$cad3 = " : Suspendida";

if ($notaTotal > 5){
$mis = "$cad1 $notaTotal $cad2";
}else{
$mis = "$cad1 $notaTotal $cad3";
}


}

--------------

Alguien me podria ayudar ?? porque la funcion no me devuelve nada ...

Aqui pongo un ejemplo de un formulario de estos 9 que menciono:

-------
<form id="form2" name="form2" method="get">
<div class="Contingut" id="7" style="display:none;">
<p Class="textContingut">
<table width="700" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td colspan="4" height="50" align="center">2on Bloc Curricular Informatica</td>
</tr>
<tr>
<td>Assignatura</td>
<td>Cr</td>
<td>Nota</td>
<td>Assignatura</td>
<td>Cr</td>
<td>Nota</td>
</tr>
<tr>
<td height="27">Administració d’Empreses</td>
<td <input type="text" id="c3" name="c0" readonly="true" style="width:100px;" value="6"/></td>
<td><input type="text" id="i211"name="t0" style="width:100px;"/></td>
<td>Algor&iacute;smica i Programaci&oacute; Avan&ccedil;ada</td>
<td <input type="text" id="c3" name="c1" readonly="true" style="width:100px;" value="4,5"/></td>
<td><input type="text" id="i212"name="t1" style="width:100px;"/>
</td>
</tr>
<tr>
<td height="27">Bases de Dades</td>
<td <input type="text" id="c3" name="c2" readonly="true" style="width:100px;" value="6"/></td>
<td><input type="text" id="i213"name="t2" style="width:100px;"/></td>
<td>DSI</td>
<td <input type="text" id="c3" name="c3" readonly="true" style="width:100px;" value="7,5"/></td>
<td><input type="text" id="i214"name="t3" style="width:100px;"/></td>
</tr>
<tr>
<td height="27">Enginyeria del Software 2</td>
<td <input type="text" id="c3" name="c4" readonly="true" style="width:100px;" value="6"/></td>
<td><input type="text" id="i215"name="t4" style="width:100px;"/></td>
<td>Estad&iacute;stica per a Inform&agrave;tics</td>
<td <input type="text" id="c3" name="c5" readonly="true" style="width:100px;" value="4,5"/></td>
<td><input type="text" id="i216"name="t5" style="width:100px;"/></td>
</tr>
<tr>
<td height="27">Estructures de Dades i Algorismes</td>
<td <input type="text" id="c3" name="c6" readonly="true" style="width:100px;" value="6"/></td>
<td><input type="text" id="i217"name="t6" style="width:100px;"/></td>
<td>Laboratori d&rsquo;Inform&agrave;tica de Gesti&oacute; 2</td>
<td <input type="text" id="c3" name="c7" readonly="true" style="width:100px;" value="6"/></td>
<td><input type="text" id="i218"name="t7" style="width:100px;"/></td>
</tr>
<tr>
<td height="27">Sistemes Operatius</td>
<td <input type="text" id="c3" name="c8" readonly="true" style="width:100px;" value="9"/></td>
<td><input type="text" id="i219"name="t8" style="width:100px;"/></td>
<td>Xarxes i Serveis</td>
<td <input type="text" id="c3" name="c9" readonly="true" style="width:100px;" value="4,5"/></td>
<td><input type="text" id="i2110"name="t9" style="width:100px;"/></td>
</tr>
</table>
<input type="text" readonly="true" style="width:100px;" value=<?php "calcula(10);" ?>/>
<input type="submit" value="Validar" style="position:absolute; left: 288px; top: 340px;"/>
<input type="button" value="Esborrar" onclick="Borra(2)" style="position:absolute; left: 588px; top: 340px;"/>
</form>

-----

Todo esta en un mismo archivo llamado "indice.php", la funcion PHP declarada arriba del todo del Body entre <? ... ?>

Muchas gracias a todos !
  #2 (permalink)  
Antiguo 20/10/2010, 05:25
Avatar de angelAparicio  
Fecha de Ingreso: julio-2009
Ubicación: Sevilla
Mensajes: 307
Antigüedad: 14 años, 9 meses
Puntos: 22
Respuesta: Formulario HTML y funcion PHP

Es que la función no tiene ningún return, así es difícil que devuelva algo

Por cierto, es mejor si envías los datos por POST, en vez de por GET.
__________________
Mis webs:
- Programador Web Autónomo
- Conciertos en Sevilla

Etiquetas: funcion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:10.