Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2007, 09:39
Avatar de rekkiem
rekkiem
 
Fecha de Ingreso: diciembre-2006
Mensajes: 30
Antigüedad: 17 años, 5 meses
Puntos: 0
Agregar+Hidden

Hola, un problema con mostrar una lista que se debe ir agregando de manera secuencial, pero no deben repetirse los elementos de esta lista. Esto es lo ke he hecho hasta el momento pero funciona a medias. Cualkier ayuda . se agradece.

Código PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<form name="form1" method="post" action="<? $_SERVER['PHP_SELF'];?>" >
  <p>Nombre <input type="text" name="textfield">
  </p>
  <p>Lugar 
    <select name="bList">
      <option>Stgo</option>
      <option>Tko</option>
      <option>Conce</option>
    </select>
    <input type="submit" name="BtnAdd" value="Agregar" >
  </p>
  <?
//----------------------Captura dato de Lista-------------------------
if(isset($_POST['BtnAdd'])){
 echo 
"cont_list".$_POST['contador_lista'];
    
$contador $_POST['contador_lista']+1;
            
    
$x=1;
    
$Flag=0;     
    while(
$x<=$contador){ //bucle busca repetidos      
      
$Band=0;
      if(
$x!=1)    {
        for(
$i=1;$i<$contador;$i++){      
           if(
$_POST['lista'.$i]==$_POST['bList']){
             echo
"<script>alert('No puede repetir los datos')</script>";
             
$Band=1;    $Flag=1;     
              }     
          }
       }

       
$hdLista='lista'.$x;
      
       
//creo los hidden dinamicos
       
if($contador==$x) {
             
$valor $_POST['bList'];
                  
        }else{
          
$valor $_POST['lista'.$x];
        }
       if(
$Band!=1){ ?> <br>
         <?=$valor?><input type="hidden" name="<? echo $hdLista ?>" value="<?=$valor?>">    
         <? 
        
}  $x=$x+1
    } 
//--------------------End While----------------------


//---------------------End If isset---------------------

if($Flag==0){ 
   
// echo "Flag".$Flag;      
    
?>
        <input name="contador_lista" type="hidden" id="contador_lista" value="<?=$contador?>"> <?           
      
echo "Cont".$contador;
    }
    
?>
  <p>
    <input type="submit" name="btnGo" value="Enviar">
  </p>
</form>



 
</body>
</html>