Foros del Web » Programando para Internet » PHP »

Paginación con SQL Server en PHP

Estas en el tema de Paginación con SQL Server en PHP en el foro de PHP en Foros del Web. Hola foreros, tengo problemas con la paginación de resultados, uso PHP y MS SQL con ADODB. El problema es que no me esta haciendo bien ...
  #1 (permalink)  
Antiguo 23/03/2010, 10:52
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 15 años, 4 meses
Puntos: 19
Busqueda Paginación con SQL Server en PHP

Hola foreros, tengo problemas con la paginación de resultados, uso PHP y MS SQL con ADODB. El problema es que no me esta haciendo bien la paginación, y le programe una actualización automatica cada 5 minutos, pero cuando actualiza pide reenviar datos o cancelar, y a veces me da error, de driver mssql, quisiera su ayuda a ver si tienen una funcion php para paginar los resultados sin que den tantos problemas como me dan a veces.

A continuación les paso lo que tengo:

De cabecera...

Código:
<?php 
$totalregistros = $db->Execute($consulta_totalregistros);
if (!$totalregistros) 
	print $db->ErrorMsg();
else
	while (!$totalregistros->EOF) {
		$total_registros = $totalregistros->fields[0];
		$totalregistros->MoveNext();	
	}	
$paginacion = ($total_registros % $columnas); //($x % $y);
if ($paginacion == 0) { 
	$desde2 = ($total_registros/$columnas); 
} else { 
	$division2 = $total_registros/$columnas;
	$division3 = explode(".",$division2);
	$valor3 = $division3[0];
	$desde2 = ($valor3)*$columnas;
}
if (!empty($_POST['valor'])) {
	$valor2 = $_POST['valor2'];
	$valor = $_POST['valor']; 
	if ($valor=="-1") { 
		if ($valor2 == "1") { 
			$desde = 0;
			$valor = 0;
		} else {
			$valor = $desde-1; 
			$desde = ($valor)*$columnas; 
		}
	}
	if ($valor=="+1") { 
		$valor = $desde+1; 
		$desde = ($valor)*$columnas; 
	}
	if ($valor=="0") { 
		$valor = 0; 
		$desde = 0; 
	} 
	if ($valor=="2") { 
		 $paginacion = ($total_registros % $columnas); //($x % $y);
		 if ($paginacion == 0) { 
		 	$desde = ($total_registros/$columnas); 
		} else { 
			$division = $total_registros/$columnas;
			$division2 = explode(".",$division);
			$valor = $division2[0];
			$desde = ($valor)*$columnas;
			$ultimo = $desde;
		}
	}
}
?>
De intermedio tengo el cuadro donde se imprimen los resultados (es muy largo para ponerlo aqui.

De pie de página...

Código:
<table width="200" border="0" align="center">
  <tr>
    <td><form id="formA" name="formA" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
  <p>
    <label>
      <input type="hidden" name="valor" id="valor" value="0"/>
      <input type="hidden" name="valor2" id="valor2" value="<?php echo $valor; ?>"/>
      <input type="image" name="primero" <?php if ($desde==0) { echo "disabled"; } ?> src="images/PRIMERO.png" style="height:20px; width:20px;"/>
    </label>
  </p>
</form></td>
    <td><form id="formB" name="formB" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" >
  <p>
    <label>
      <input type="hidden" name="valor" id="valor" value="-1"/>
      <input type="hidden" name="valor2" id="valor2" value="<?php echo $valor; ?>"/>
      <input type="image" name="anterior"   <?php if ($desde==0) { echo "disabled"; } ?> src="images/MENOS.png" style="height:30px; width:30px;"/>
    </label>
  </p>
</form></td>
    <td><form id="formC" name="formC" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
  <p>
    <label>
      <input type="hidden" name="valor" id="valor" value="+1"/>
      <input type="hidden" name="valor2" id="valor2" value="<?php echo $valor; ?>"/>
      <input type="image" name="siguiente"   <?php  if ($desde==$desde2) { echo "disabled"; } ?> src="images/MAS.png" style="height:30px; width:30px;"/>
    </label>
  </p>
</form></td>
    <td><form id="formD" name="formD" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
  <p>
    <label>
      <input type="hidden" name="valor" id="valor" value="2"/>
      <input type="hidden" name="valor2" id="valor2" value="ultimo"/>
      <input type="image" name="ultimo"  <?php if ($desde==$desde2) { echo "disabled"; } ?> src="images/ULTIMO.png" style="height:20px; width:20px;"/>
    </label>
  </p>
</form></td>
  </tr>
</table>
  #2 (permalink)  
Antiguo 26/04/2010, 07:35
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 15 años, 4 meses
Puntos: 19
Respuesta: Paginación con SQL Server en PHP

Ya que nadie me pudo ayudar, solucione el problema usando un arreglo a continuación les pego el codigo a la gente para que los ayuden

Código:
<?php $sql = "SELECT     RVMservicio.servicio AS TIPO, RVMservicio.correlativo AS 'No. PROYECTO', RVMservicio.nombrebarco AS BARCO, RVMagente.compania AS AGENTE, 
                      RVMservicio.fecha_llegada AS ETA, RVMservicio.fecha_salida AS ETD, RVMpuertos.puerto AS PUERTO, RVMservicio.estatus, 
                      RVMservicio.tecnico AS IDTEC
FROM         RVMservicio INNER JOIN
                      RVMagente ON RVMservicio.compania_agente = RVMagente.id_agente INNER JOIN
                      RVMpuertos ON RVMservicio.puerto = RVMpuertos.id_puerto
WHERE     (RVMservicio.estatus <> 'Canceled') AND (RVMservicio.estatus <> 'Finished') ".$sql2."
ORDER BY RVMservicio.correlativo DESC";
$servicios = $db->Execute($sql);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RVM</title>
</head>

<body>
<p>
  <?php
$i = 0;
$arreglo = array();
$tablas = array();
if (!$servicios) {
	print $db->ErrorMsg();
} else {
	while (!$servicios->EOF) {
		$i++;
		$enlace1 = "<center>
    <a href='imprimir.php?recordID=".$servicios->fields[1]."' style='text-decoration:none; border:none;' target='_blank'><img src='images/print.png' width='30' height='30' style='text-decoration:none; border:none;' alt='Print'/></a>
  </center>";

		if ($servicios->fields[7]=="Canceled") { $estatus = "Cancelado"; }
		if ($servicios->fields[7]=="Finished") { $estatus = "Finalizado"; }
		if ($servicios->fields[7]=="Unasigned") { $estatus = "Oficina Preasignada"; }
		if ($servicios->fields[7]=="PreFactured") { $estatus = "Por Facturar"; }
		if ($servicios->fields[8]==0) { if ($servicios->fields[7]=="Asigned") { $estatus = "Oficina Asignada"; } }
		if ($servicios->fields[8]!=0) { if ($servicios->fields[7]=="Asigned") { $estatus = "T&eacute;cnico Preasignado"; } }
		if ($servicios->fields[7]=="Technichian Asigned") { $estatus = "T&eacute;cnico Asignado"; }
		if ($servicios->fields[7]=="Technician Asigned") { $estatus = "T&eacute;cnico Asignado"; }
		if ($servicios->fields[7]=="Waiting for parts") { $estatus = "Por Partes"; }
		if ($servicios->fields[7]=="By Monitoring") { $estatus = "Por Seguimiento"; }
		$arreglo[$i] = array('ENLACE 1' => $enlace1,'TIPO' => $servicios->fields[0], 'No. PROYECTO' => $servicios->fields[1], 'BARCO' => $servicios->fields[2], 'AGENTE' => $servicios->fields[3], 'ETA' => $servicios->fields[4], 'ETD' => $servicios->fields[5], 'PUERTO' => $servicios->fields[6], 'ESTADO' => $estatus, 'TEC' => $servicios->fields[8]);
		$servicios->MoveNext();
	}
	
}
$perpage = 10; //Obviously you would want to change this to something higher, depending on the content.
if(isset($_GET['start'])) $start = $_GET['start']; else $start = 0;
$numposts = count($arreglo);
$data = array_slice($arreglo, $start, $perpage);
?>
</p>
<p>&nbsp;</p>
<table border="0" align="center">
  <tr bgcolor="#000000" class="asd">
	<td align="center"><strong>&nbsp;</strong></td>
    <td align="center"><strong>TIPO</strong></td>
    <td align="center"><strong>No. PROYECTO</strong></td>
    <td align="center"><strong>BARCO</strong></td>
    <td align="center"><strong>AGENTE</strong></td>
    <td align="center"><strong>ETA</strong></td>
    <td align="center"><strong>ETD</strong></td>
    <td align="center"><strong>PUERTO</strong></td>
    <td align="center"><strong>ESTADO</strong></td>
    <td align="center"><strong>&nbsp;</strong></td>
    <td align="center"><strong>&nbsp;</strong></td>
    <td align="center"><strong>&nbsp;</strong></td>
    <td align="center"><strong>&nbsp;</strong></td>
  </tr><?php
foreach($data as $k => $v)
{ ?>
<?php 
	$fechadesalida = $data[$k]['ETD'];
	// Comparo las fechas en formato UNIX y especifico el color de la tabla.
	$fecha_actual=mktime(0,0,0,date('m'),date('d'),date('Y'));
	$fecha_operar=$fechadesalida;
	list($dia,$mes,$año)=explode("/",$fecha_operar);
	$fecha_operar=mktime(0,0,0,$mes,$dia,$año);
	if ($fecha_actual > $fecha_operar){
		echo "<tr class='Rojo'>";
	}
	if ($fecha_actual < $fecha_operar){
		echo "<tr class='Verde'>";
	}
	if ($fecha_actual == $fecha_operar){
		echo "<tr class='Amarillo'>";
	}
	if ($data[$k]['ESTADO'] == 'Por Facturar'){
		echo "<tr class='PreFacturar'>";
	}
?>
    <td><?php echo $data[$k]['ENLACE 1']; ?></td>
    <td><?php echo $data[$k]['TIPO']; ?></td>
    <td><?php echo $data[$k]['No. PROYECTO']; ?></td>
    <td><?php echo $data[$k]['BARCO']; ?></td>
    <td><?php echo $data[$k]['AGENTE']; ?></td>
    <td><?php echo $data[$k]['ETA']; ?></td>
    <td><?php echo $data[$k]['ETD'];?></td>
    <td><?php echo $data[$k]['PUERTO']; ?></td>
    <td><?php echo $data[$k]['ESTADO']; ?></td>
    <?php if ($data[$k]['ESTADO'] == 'Por Facturar') { ?>
	<td width="30">&nbsp;</td>
    <td width="30">&nbsp;</td>
    <td width="30">&nbsp;</td>
    <td width="30">&nbsp;</td>
	<?php } ?>
    <?php 
	if(empty($_SESSION['oficina'])){
	if (empty($_SESSION['tecnico'])) { 
	if ($data[$k]['ESTADO'] == 'Oficina Preasignada') {
	?>
	<td width="30"><?php  if($nivel==1) {?><center>
      <span class="textoscuadros"><a href='asignado.php?recordID=<?php echo $data[$k]['No. PROYECTO']."_Asigned"; ?>'><img src="images/Imagen_Asignar.png" width="30" height="30" style="border:none"/></a> </span>
    </center><?php } ?></td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='reasignar_servicio.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_ReAsignar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='modificar_todo.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Modificar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><?php if ($nivel==1) {?><center>
      <span class="textoscuadros"><a href='cancelaciones.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Cancelar.png" width="30" height="30" style="border:none"/></a> </span>
    </center><?php } else { echo ""; } ?></td>
<?php  	} 
		}
		}
?>
    <?php if ($data[$k]['ESTADO'] == 'Oficina Asignada' or $data[$k]['ESTADO'] == 'T&eacute;cnico Preasignado') { ?>
	<td width="30"><?php if($data[$k]['ESTADO'] == 'T&eacute;cnico Preasignado') { ?>
	<?php  if ($data[$k]['TEC']!=0) { if($nivel!=1) { ?>
    <a href="asignarhojatrabajo2.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>_tec"><img src="images/Imagen_Asignar.png" width="30" height="30" style="border:none"/></a>
    <?php }  }?>
	<?php } ?></td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='reasignar_servicio.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_ReAsignar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='modificar_todo.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Modificar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><?php if ($nivel==1) {?><center>
      <span class="textoscuadros"><a href='cancelaciones.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Cancelar.png" width="30" height="30" style="border:none"/></a> </span>
    </center><?php } else { echo ""; } ?></td>
	<?php } ?>
    <?php if ($data[$k]['ESTADO'] == 'T&eacute;cnico Asignado') { ?>
	<td width="30">&nbsp;</td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='reasignar_servicio.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_ReAsignar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><center>
      <span class="textoscuadros"><a href='modificar_todo.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Modificar.png" width="30" height="30" style="border:none"/></a> </span>
    </center></td>
    <td width="30"><?php if ($nivel==1) {?><center>
      <span class="textoscuadros"><a href='cancelaciones.php?recordID=<?php echo $data[$k]['No. PROYECTO']; ?>'><img src="images/Imagen_Cancelar.png" width="30" height="30" style="border:none"/></a> </span>
    </center><?php } else { echo ""; } ?></td>
	<?php } ?>
  </tr>
    
<?php }?>
</table>
<?php

$text = "";
if($start > 0)
{
	$text .= '<a href="cartelera5.php?start='.($start - $perpage).'"><img src="images/MENOS.png" style="height:30px; width:30px; border:none;" /></a>';
}
if($start > 0 && $numposts > $perpage && $start < $numposts - $perpage)
{
	$text .= ' | ';
}
if($numposts > $perpage && $start < $numposts - $perpage)
{
	$text .= '<a href="cartelera5.php?start='.($start + $perpage).'"><img src="images/MAS.png" style="height:30px; width:30px; border:none;" /></a>';
}
echo $text;
?>
</body>
</html>
  #3 (permalink)  
Antiguo 26/04/2010, 07:37
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 15 años, 4 meses
Puntos: 19
Respuesta: Paginación con SQL Server en PHP

Ah y pego el enlace aca el enlace que me ayudo (en ingles) porque en el post anterior no podia poner mas nada

http://1scripts.net/blog/2008/07/18/pagination-in-php/

Etiquetas: adodb, paginacion, server, sql
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 20:52.