Foros del Web » Programando para Internet » PHP »

Validacion con bd con if

Estas en el tema de Validacion con bd con if en el foro de PHP en Foros del Web. Buenas , quisiera saber si ustedes me pueden ayudar con este problema, tengo una tabla en html y php que se conecta la bd eso ...
  #1 (permalink)  
Antiguo 06/03/2014, 11:50
 
Fecha de Ingreso: enero-2014
Mensajes: 33
Antigüedad: 10 años, 3 meses
Puntos: 0
Validacion con bd con if

Buenas , quisiera saber si ustedes me pueden ayudar con este problema, tengo una tabla en html y php que se conecta la bd eso sin problema pero quiero validar cuando dicha sentencia tra valores vacios y eso ya esta logrado pero el problema es que si me valida pero siempre que me muestra los datos no me muestra el primer registro, me explico la tabla tira valores sin probelma y valida sin problema pero no me muestra el primer registro siempre me muestra del segundo en adelnate y primero como si no existiera, les pondre mi codigo de como lo hago para ver si me pueden ayudar

Código PHP:
<?php
include_once "../Class/conexion2.php";
@
$f $_REQUEST['datepicker'];


$sql="SELECT s.Grupo, 

              ROUND(SUM(v.VentaActual) / 1000, 3) AS VentaActual,

              ROUND(SUM(v.VentaDiaAnt) / 1000, 3) AS VentaDiaAnt,

              ROUND(SUM(v.VentaSemAnt) / 1000, 3) AS VentaSemAnt,

              ROUND(SUM(v.VentaAnoAnt) / 1000, 3) AS VentaAnoAnt,

              ROUND(SUM(v.VentaBisAnt) / 1000, 3) AS VentaBisAnt

FROM VentasSucursal v

JOIN Sucursal s ON v.Sucursal = s.Sucursal

WHERE v.FechaEmision = '$f'

GROUP BY s.Grupo

ORDER BY 2"
;

$resultado=odbc_exec($conn,$sql);




if(
$rest=odbc_fetch_array($resultado) == NULL)
{
    
     echo 
"<tr>
     <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
     <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
     <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
     <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
     <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
    <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
    <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
    <td  width=50><font SIZE=2  color=white>No existen registros para la fecha: "
,$f,"</td>
      
      
     
     </tr>"
;  
}
else
{

while(
$row=odbc_fetch_array($resultado))
            {
                
$x $row['VentaBisAnt'];
                
$y $row['VentaAnoAnt'];
                
$z $row['VentaActual'];
                
$rs $y $x;
                @
$rs2 = (1-$x/$y)*100;
                
$rs3=$z-$y;
                @
$cr = (1-$y/$z)*100;
                
                
//Suma
                
@$sumaVB $sumaVB $x;
                @
$sumaVAA $sumaVAA $y;
                @
$sumaVA $sumaVA $z;
                @
$sumaDF1 $sumaDF1  $rs;
                @
$sumaDF1P $sumaDF1P $rs2;
                @
$sumaDF2 $sumaDF2 $rs3;
                @
$sumaDF2P $sumaDF2P $cr;
                
                
//Suma
                
                
                
                
echo "<tr>";
                
                
                
                echo 
"<td><font SIZE=2 color=white>",$row['Grupo'],"</td>";
                
                
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($row['VentaBisAnt'],2),"</td>";
                
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($row['VentaAnoAnt'],2),"</td>";
                
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($row['VentaActual'],2),"</td>";
                
                
                
                
                if(
$rs >= 0)
                {
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($rs,2),"</td>";
                }
                else
                {
                echo 
"<td><p align=right><font SIZE=2 color=red>",round($rs,2),"</font></td>";
                
                
                }
                if(
$rs2 >= 0)
                {
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($rs2,2),"</td>";
                }
                else
                {
                echo 
"<td><p align=right><font SIZE=2 color=red>",round($rs2,2),"</font></td>";
                
                }
                if(
$rs3 >= 0)
                {
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($rs3,2),"</td>";
                }
                else
                {
                
                echo 
"<td><p align=right><font color=red>",round($rs3,2),"</font></td>";
                }
                if(
$cr >= 0)
                {
                echo 
"<td><p align=right><font SIZE=2  color=white>",round($cr,2),"</td>";
                }
                else
                {
                
                echo 
"<td><p align=right><font SIZE=2 color=red>",round($cr,2),"</font></td>";
                }
                
                echo 
"</tr>";
                
                
            }
    }
            
            
            


?>
  #2 (permalink)  
Antiguo 06/03/2014, 19:50
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Validacion con bd con if

Código PHP:
Ver original
  1. if($rest=odbc_fetch_array($resultado) == NULL)

Esa línea avanza el apuntador del juego de resultados, luego, cuando haces el while, comienza por el segundo registro.

Busca en el manual de PHP, seguramente hay una función para saber cuantas filas devolvió la consulta y cambiar el if. En mysql la función es mysql_num_rows(), en mysqli es mysqli_num_rows() y supongo que también lo hay para odbc.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: bd, fecha, html, registro, select, sql, tabla, validacion
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 05:45.