Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2009, 09:55
Avatar de Hamn
Hamn
 
Fecha de Ingreso: marzo-2008
Ubicación: Cali-Colombia
Mensajes: 212
Antigüedad: 16 años, 1 mes
Puntos: 1
Esta matriz no me funciona

Amigos tengo esta matriz donde pido datos de un paciente, donde primero le pido a la persona que digita ponga el numero de pacientes a digitar, luego que ingrese los datos solicitados y luego de aceptar para mostrar los resultados. pero no se en que falla. si deshabilito la opcion de poner los campos a digitar funciona excelente...

Una manito amigos aca dejo el codigo a ver que puedo tener fallando...

Aca sin deshabilitar los campos de llenado
Código PHP:
<?php
extract
($_POST); // recibe variables POST se utiliza solo en formularios
$pcte=3;
$glucosa=array(); //definimos matriz
$niv='nivel['// se asigna una cadena de caracteres a una variable constante
$nom='nomb[';
$eva='eval[';
$res='resultado[';
$pcte=0;


echo
"<BODY bgcolor=#A9F5D0>"
echo
"<br>";
echo
"<center>";
echo
"<form name=cant id=cant action='glucosa.php?' method=post> ";
echo
"<h2>DIGITE LA CANTIDAD DE PACIENTES:</h2><br> ";
echo
"<input type=text name=$pcte size='10' value='$pcte'>"
echo
"<input type=submit value='Entrar'> ";
echo
"</form>"

$pcte $_POST["$pcte"]; if(!isset($pcte)){$pcte='';}; 

if(!isset(
$act))
   {
$act=0;}
echo
"<center>";
echo
"<form name=glucosa id=glucosa method=post action='glucosa.php?'>"//Formulario. Envia informacion
echo "<h2>NOMBRE Y APELLIDOS - NIVEL DE GLUCOSA DEL PACIENTE</h2><br>";
    for(
$fila=0$fila<$pcte$fila++)
    {
        
$def1=$nom.$fila.']';if(!isset($$def1)){$$def1='';} // $def1 variable de trabajo y la asigno
        
$def2=$niv.$fila.']';if(!isset($$def2)){$$def2='';}
        
        if(
$act==1){$x=$nomb[$fila]; $y=$nivel[$fila];}
        else{
$x='';$y='';}
        echo
"<input type=text name=$def1 size=30 value='$x'>";
        echo
"<input type=text name=$def2 size=4 value='$y'>";
        echo
"<br>";
    }
    echo
"<br>";  
    echo
"<input type=hidden name=act value=1>";// campo oculto
    
echo"<input type=submit value='aceptar'>";
 echo
"</form>";

if(
$act==1)
{ echo
"<table border=1 bgcolor=#A9F5D0>";
  echo
"<tr >";
        echo 
"<td><h3>NOMBRE Y APELLIDOS DEL PACIENTE</h3></td>";
        echo 
"<td><h3>NIVEL DE GLUCOSA</h3></td>";
        echo 
"<td><h3>RESULTADO</h3></td>";
        echo
"</tr>";
        
    for(
$fila=0$fila<$pcte$fila++)
    {
        
$def3$res.$fila.']';if(!isset($$def3)){$$def3='';} //variable de trabajo
        
echo "<tr>";
        echo 
"<td>$nomb[$fila]</td>";
        echo 
"<td>$nivel[$fila]</td>";
           
//calculo de resultado
            
if($nivel[$fila]>&& $nivel[$fila]<70)
            {
                echo 
"<td>EL PACIENTES ES HIPOGLICEMICO</td><br>";
            }
            else
            {
                if(
$nivel[$fila]>69 && $nivel[$fila]<121)
                {
                    echo 
"<td>EL NIVEL DE GLUCOSA EN EL PACIENTE ES NORMAL</td><br>";
                }
                else
                {
                    if(
$nivel[$fila]>120)
                    {
                        echo 
"<td>EL PACIENTE ES DIABETICO.</td><br>";
                    }
                   
                }
            }
        echo
"</tr>";
    }
    echo
"</table>";
echo
"</center>";    
}echo
"</BODY>"
?>
Aca con los campos deshabilitados miren la diferencia
Código PHP:
<?php
extract
($_POST); // recibe variables POST se utiliza solo en formularios
$pcte=3;
$glucosa=array(); //definimos matriz
$niv='nivel['// se asigna una cadena de caracteres a una variable constante
$nom='nomb[';
$eva='eval[';
$res='resultado[';
//$pcte=0;

/*
echo"<BODY bgcolor=#A9F5D0>"; 
echo"<br>";
echo"<center>";
echo"<form name=cant id=cant action='glucosa.php?' method=post> ";
echo"<h2>DIGITE LA CANTIDAD DE PACIENTES:</h2><br> ";
echo"<input type=text name=$pcte size='10' value='$pcte'>"; 
echo"<input type=submit value='Entrar'> ";
echo"</form>"; 
*/
//$pcte = $_POST["$pcte"]; if(!isset($pcte)){$pcte='';}; 

if(!isset($act))
   {
$act=0;}
echo
"<center>";
echo
"<form name=glucosa id=glucosa method=post action='glucosa.php?'>"//Formulario. Envia informacion
echo "<h2>NOMBRE Y APELLIDOS - NIVEL DE GLUCOSA DEL PACIENTE</h2><br>";
    for(
$fila=0$fila<$pcte$fila++)
    {
        
$def1=$nom.$fila.']';if(!isset($$def1)){$$def1='';} // $def1 variable de trabajo y la asigno
        
$def2=$niv.$fila.']';if(!isset($$def2)){$$def2='';}
        
        if(
$act==1){$x=$nomb[$fila]; $y=$nivel[$fila];}
        else{
$x='';$y='';}
        echo
"<input type=text name=$def1 size=30 value='$x'>";
        echo
"<input type=text name=$def2 size=4 value='$y'>";
        echo
"<br>";
    }
    echo
"<br>";  
    echo
"<input type=hidden name=act value=1>";// campo oculto
    
echo"<input type=submit value='aceptar'>";
 echo
"</form>";

if(
$act==1)
{ echo
"<table border=1 bgcolor=#A9F5D0>";
  echo
"<tr >";
        echo 
"<td><h3>NOMBRE Y APELLIDOS DEL PACIENTE</h3></td>";
        echo 
"<td><h3>NIVEL DE GLUCOSA</h3></td>";
        echo 
"<td><h3>RESULTADO</h3></td>";
        echo
"</tr>";
        
    for(
$fila=0$fila<$pcte$fila++)
    {
        
$def3$res.$fila.']';if(!isset($$def3)){$$def3='';} //variable de trabajo
        
echo "<tr>";
        echo 
"<td>$nomb[$fila]</td>";
        echo 
"<td>$nivel[$fila]</td>";
           
//calculo de resultado
            
if($nivel[$fila]>&& $nivel[$fila]<70)
            {
                echo 
"<td>EL PACIENTES ES HIPOGLICEMICO</td><br>";
            }
            else
            {
                if(
$nivel[$fila]>69 && $nivel[$fila]<121)
                {
                    echo 
"<td>EL NIVEL DE GLUCOSA EN EL PACIENTE ES NORMAL</td><br>";
                }
                else
                {
                    if(
$nivel[$fila]>120)
                    {
                        echo 
"<td>EL PACIENTE ES DIABETICO.</td><br>";
                    }
                   
                }
            }
        echo
"</tr>";
    }
    echo
"</table>";
echo
"</center>";    
}echo
"</BODY>"
?>