Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/08/2010, 11:35
patypecas
 
Fecha de Ingreso: julio-2010
Mensajes: 91
Antigüedad: 13 años, 9 meses
Puntos: 1
contar filas con php

buenas tardes,

Tengo el siguiente código con el cual estoy leyendo un archivo de Excel, resulta que tengo que hacer un conteo de cuantas filas presentan alguna inconsistencias o alguno de los errores que están definidos como campos vacios, fechas invalidas, estructuras no validas, y también un conteo de cuantas filas están perfectas con todas las condiciones ok.

El codigo es el siguiente


Código PHP:
<?php
include_once ("../ExcelReader/Excel/reader.php");
include (
"conexion.php");
date_default_timezone_set("America/Bogota");
$fechacargue date("Y-m-d H:i:s"); 
$type explode'.'$_FILES['arcRem']['name'] );
if( 
$type[1] != 'xls' )
{
    echo 
'<script> alert("Por favor seleccione un Archivo Excel 2003");document.location.href="cargue_inventarioBBVA.php";</script>';
    exit;
}
$nombre $_FILES['arcRem']['tmp_name'];
$datos = new Spreadsheet_Excel_Reader();
$datos->read($nombre);
$arreglo $datos->sheets[0]['cells'];

foreach( 
$arreglo as $var=>$new)
{
    
$campos $arreglo[$var];

    for( 
$i 1$i 41$i++ )    
    {
        echo 
$campos[$i].'<br>';
        if( 
$i == 40 ) echo '<hr>';
    
    }

        if (
$campos[2]==""
        {
            echo 
"NUMERO DE CAJA VACIO ";
            echo 
"-";
        }    
                
        if (
$campos[3]==""
        {
            echo 
"TIPO DOCUMENTAL VACIO ";
            echo 
"-";
        }
        
        if (
$campos[5]==""
        {
            echo 
"NOMBRE UNIDAD VACIO ";
            echo 
"-";
        }
        
        if (
$campos[6]==""
        {
            echo 
"OFICINA VACIO ";
            echo 
"-";
        }
        
        if (
$campos[7]==""
        {
            echo 
"EMPRESA VACIO ";
            echo 
"-";
        }
        
        if (
$campos[38]==""
        {
            echo 
"CODIGO UNIDAD VACIO ";
            echo 
"-";
        }
    
        
//ESTRUCTURAS
        
$exprCA="/^02630001005[0-9]{8}$/";
        
$exprUD="/^02630[0-9]{8}$/";

        if (
$campos[2]!=""
        {
            if( !
preg_match ($exprCA$campos[2])) 
            {
              echo 
"<br>Estructura NUMERO DE CAJA no valida";
                              
            } 
        }
        
        if (
$campos[38]!=""
        {
            if( !
preg_match ($exprUD$campos[38])) 
            {
              echo 
"<br>Estructura UNIDAD DOCUMENTAL no valida";
              
                
            } 
        }
        
        
//CONSULTAR OTRAS TABLAS        

        
if ($campos[6]!=""
        {
            
$cnsOf "select * from oficina WHERE idoficina = '$campos[6]' ";
            
$rst=mysql_query($cnsOf,$link);
            
$num_filas mysql_num_rows($rst);
            
            if(
$num_filas!=0)
            {
                
//echo "<br>Oficina $campos[6] si existe";
            
}
        }
        
        if (
$campos[7]!=""
        {
            
$cnsEmp "select * from empresa WHERE nombre = '$campos[7]' ";
            
$rst1=mysql_query($cnsEmp,$link);
            
$num_filas1 mysql_num_rows($rst1);
            
            if(
$num_filas1!=0)
            {
                
//echo "<br>Empresa $campos[7] si existe";
            
}
        }
        
        if (
$campos[3]!=""
        {
            
$cnsTip "select * from tipologia WHERE nombre = '$campos[3]' ";
            
$rst2=mysql_query($cnsTip,$link);
            
$num_filas2 mysql_num_rows($rst2);
            
            if(
$num_filas2!=0)
            {
                
//echo "<br>Tipologia $campos[3] si existe";
            
}
        }
        
            if ((
$campos[3]=="Analisis de Riesgo")|| ($campos[3]=="Análisis de Riesgo"))
            {
                
$tipo="Aná¡lisis de Riesgo";
                
$cambio $campos[3];
                
//echo "<br>";
                //echo "Tipolo: $cambio";
                
$cambio $tipo
                
//echo "--Cambio  $cambio";
            
}
        
        if (
$campos[16]!=""
        {
            
$cnsNov "select * from novedad WHERE nombre = '$campos[16]' ";
            
$rst3=mysql_query($cnsNov,$link);
            
$num_filas3 mysql_num_rows($rst3);
            
            if(
$num_filas3!=0)
            {
                
//echo "<br>Novedad $campos[16] si existe es:";
            
}
                while(
$rows1=mysql_fetch_array($rst3))
                {
                    
$idnovedad=$rows1['idnovedad'];
                    
//echo $idnovedad;
                
}
        }
        
            else
            {
                
$novcero="-1";
                
$nuevo $campos[16];
                
//echo "<br>";
                //echo "Vacio Nove: $nuevo";
                
$nuevo $novcero
                
//echo "--Ahora Nove $nuevo";
            
}
        
        
//validar fechas
        
$sep "[\/]";
        
$req "#^(((0?[1-9]|1\d|2[0-8]){$sep}(0?[1-9]|1[012])|(29|30){$sep}(0?[13456789]|1[012])|31{$sep}(0?[13578]|1[02])){$sep}(19|[2-9]\d)\d{2}|29{$sep}0?2{$sep}((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$#";
        
        if (
$campos[8]!=""
        {
            
//echo "<br>Fecha_ini $campos[8]";
            
$fechaini str_replace("/","-",$campos[8]);
            
            if( !
preg_match ($req$campos[8])) 
            {
              echo 
"<br>FechaIn no valida";                
            } 
            else
            {
            
//echo "<br> Fecha_Ini Valida: $fechaini";
            
}
        }
        
        if (
$campos[9]!=""
        {
            
//echo "<br>Fecha_Fin $campos[9]";
            
$fechafin str_replace("/","-",$campos[9]);
            
            if( !
preg_match ($req$campos[9])) 
            {
              echo 
"<br>FechaFin no valida";                
            } 
            else
            {
            
//echo "<br> Fecha_Fin Valida: $fechafin";
            
}
        }    
        
        if (
$campos[15]!=""
        {
            
//echo "<br>Fecha_Fin $campos[9]";
            
$fecharecol str_replace("/","-",$campos[15]);
            
            if( !
preg_match ($req$campos[15])) 
            {
              echo 
"<br>FechaRec no valida";                
            } 
            else
            {
            
//echo "<br> Fecha_Recol Valida: $fecharecol";
            
}
        }        
        
        if (
$campos[19]!=""
        {
            
//echo "<br>Fecha_Fin $campos[9]";
            
$fechaenv str_replace("/","-",$campos[19]);
            
            if( !
preg_match ($req$campos[19])) 
            {
              echo 
"<br>FechaEnv no valida";                
            } 
            else
            {
            
//echo "<br> Fecha_Env Valida: $fechaenv";
            
}
        }        
        echo 
"<br>";
        echo 
'<hr>';
    
}    
//exit;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
  <title>Resultados Cargue Inventario</title>
  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
a:link {
    color: #000033;
    text-decoration: none;
}
a:visited {
    text-decoration: none;
    color: #000033;
}
a:hover {
    text-decoration: none;
    color: #000033;
}
a:active {
    text-decoration: none;
    color: #000033;
}
a {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size: 12px;
}
-->
</style></head>

<body>
<form name="form1" method="post" action="carguebbva.php">
  <p>
    <?php 

$filas 
$datos->sheets[0]['numRows'];
//quitar encabezados
$totalregistros $filas 1;

echo 
"<table width='327' border='0' align='center'>";
echo 
"<tr>";
echo 
"<td><img src='img/Logo_MTI.JPG' width='280' height='57'/></td>";
echo 
"<td><img src='img/logo.JPG' width='168' height='60' /></td>";
echo 
"</tr>";
echo 
"</table>";
echo 
"<br><br><br><br>";

echo 
"<table width='513' border='1' align='center' cellspacing='0' bordercolor='#DAEFA3'>";
echo 
"<tr>";
echo 
"<td width='200' bgcolor='#F8FCED'><strong>Total Registros: $totalregistros</strong></td>";
echo 
"<td width='156' bgcolor='#F8FCED'><strong>Lineas con error: </strong></td>";
echo 
"<td width='143' bgcolor='#F8FCED'><strong>Lineas Correctas: </strong></td>";
echo 
"</tr>";
//exit;
echo "<tr>";

echo 
"<td>";

echo 
"</td>";

echo  
"<td align='center'><a href='errores.php'><br>Ver Errores <br><br></a></td>";

echo 
"<td>";
echo 
"</td>";

echo 
"</tr>";
echo 
"</table>";


echo 
"<table width='268' border='0' align='center'>";
echo 
"<tr>";
echo 
"<br>";
echo 
"<td width='89'><div align='center'>";
echo 
"<input type='submit' name='Cargar' value='Subir Archivo'>";
echo 
"</div></td>";
echo 
"<td width='67'><div align='center'>"?>
<input type="button" name="button" id="button" value="Cancelar" onclick="document.form1.action='cargue_inventarioBBVA.php';{form1.submit();}"/>
<?php echo "</div></td>";
echo 
"</tr>";
echo 
"</table>";

////////////////
function validarFecha($fecha){
$sep "[\-]";
$req "#^(((0?[1-9]|1\d|2[0-8]){$sep}(0?[1-9]|1[012])|(29|30){$sep}(0?[13456789]|1[012])|31{$sep}(0?[13578]|1[02])){$sep}(19|[2-9]\d)\d{2}|29{$sep}0?2{$sep}((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$#";
   
   if( 
preg_match($req$fecha)) return true;
   else return 
false;
}
?>
  </p>
</form>
</body>
</html>

Gracias por la colaboracion