Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/06/2011, 22:26
Avatar de gildus
gildus
 
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 9 meses
Puntos: 105
Respuesta: [Ayuda]Lectura de Archivo txt

Te dejo algo que modifique y lo revisas:

index.html
Código HTML:
Ver original
  1. <form action="listado.php" method="post" id="departamentos" name="departamentos">
  2.         <table width="408" border="1">
  3.           <tr>
  4.             <td width="200" height="173" align="center"><b>DEPARTAMENTOS</b></td>
  5.             <td width="192"><input type="checkbox" name="departamentos" value="Contabilidad">Contabilidad
  6.             <br />
  7.             <input type="checkbox" name="departamentos" value="Sistemas" <? if(isset($_POST['departamentos']) && $_POST['departamentos']=='Sistemas') echo 'checked';?>>Sistemas
  8.             <br />
  9.             <input type="checkbox" name="departamentos" value="Mercadeo" <? if(isset($_POST['departamentos']) && $_POST['departamentos']=='Mercadeo') echo 'checked';?>>Mercadeo
  10.             <br />
  11.             <input type="checkbox" name="departamentos" value="Recursos Humanos" <? if(isset($_POST['departamentos']) && $_POST['departamentos']=='Recursos Humanos') echo 'checked';?>>Recursos Humanos
  12.        
  13.             </td>
  14.            
  15.           </tr>
  16.           <tr>
  17.             <td height="39" colspan="2" align="center"><input type="submit" name="Submit" value="Listar"> </td>
  18.           </tr>
  19.         </table>
  20.      
  21.       </form>


listado.php
Código PHP:
<?
if(isset($_POST["departamentos"]) && !empty($_POST["departamentos"]))
{    include 
"empleados.class.php";
        
$departamentos trim($_POST["departamentos"]);
    
$empleados = new Empleados($departamentos);
    
    
$resultados $empleados->listar_departamento($departamentos);
    echo 
'<center>';
    echo 
'<h2>Listado de Empleados</h2>';
    
    foreach (
$resultados as $depas
    {     foreach (
$depas as $item)
            echo 
$item.',';
        echo 
'<br>';
    }
}

echo 
'</center>';

?>

empleados.class.php
Código PHP:
class Empleados {


    function 
listar_departamento($departamentos) {
        
        
$archivo 'empleados.txt';
        
$fp fopen($archivo,'r');

        
//$arreglo = array();
        
$i 0;
        
$cadena = array();
        while (!
feof($fp)) {    
            while(
$a fgetcsv($fp1000","))
            { 
              if(
$a[4]==$departamentos)
              { 
                
$cadena[] = $a;
                
//$i++;
              
}
            }
    }

    
fclose($fp);

        
/*foreach ($cadena as $emp) 
        {

            foreach($emp as $item)
                echo  $item."<br>";
            
        }
        */
        
return $cadena;

    }



Saludos
__________________
.: Gildus :.