Re: Pagination problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Jenaro:
First off all (i'ts not exactly your question), but i think you don't
need to make this big array:

$my_array[] ="";
while ($row = mssql_fetch_object($rs)){
       $my_array[]="$row->tId";
}

'cause you don't need it... you may directly do something like this:
$counter=0;
while ($row=mssql_fetch_row($rs)) {
  if (($counter>=$start) and ($counter<($start+ $Page_Size)) {
    echo "<tr>";
    //There you go: Show all fields, one to each cell
    echo "<td>" . implode("</td><td>",$row) . "</td>";
    echo "</tr>\n";
 }
}

To read: http://www.php.net/implode
            http://ar.php.net/mssql_fetch_row

Pablo.

On 9/2/05, Jenaro Centeno Gómez <jcenteno@xxxxxxxxxxxx> wrote:
>  Hello everybody,
>  
>  This is my first message to the list and as usual is to try to solve a
> problem.
>  
>  I am using PHP+IIS+SQLServer on windows platform (no choice at the moment
> :(...)
>  Wel, I am trying to paginate some results this is the code:
>  
>  <?
>  $conn = mssql_connect("myserver", "myuser", "mypassword");
>  mssql_select_db("database");
>  $Page_Size = 20;
>  
>  $page = $_GET["page"];
>  if (!$page) {
>      $start = 0;
>      $page=1;
>  }
>  else {
>      $start = ($page - 1) * $Page_Size;
>  }
>  //This is my query, ordered of course
>  $ssql = "select * from table ORDER by Name";
>  $rs = mssql_query($ssql,$conn);
>  $total_records = mssql_num_rows($rs);
>  
>  $total_pages = ceil($total_records / $Page_Size);
>  
>  echo "Número de registros encontrados: " . $total_records . "<br>";
>  echo "Se muestran páginas de " . $Page_Size . " registros cada una<br>";
>  echo "Mostrando la página " . $page . " de " . $total_pages . "<p>";
>  
>  $rs = mssql_query($ssql,$conn);
>  
>  $my_array[] ="";
>  while ($row = mssql_fetch_object($rs)){
>          $my_array[]="$row->tId";
>  }
>  
>  mssql_free_result($rs);
>  mssql_close($conn);
>  
>  $contarray=1;
>  
>  The extracted data in the query is sent to the array
>  and here is my problem because I need to know how to send all the fields to
> put
>  every field in a different cell in the table, no just one field
>  
>  foreach ($my_array as $idarray=> $Id){
>      //this is my verification used instead of the LIMIT clausule of mysql
>  
>      if ($idarray > $start && $contarray <= $Page_Size){
>          echo "<tr><td>$Id</td>";
>         $contarray++;
>      }
>  }
>  ?>
>  </table>
>  <?
>  if ($total_pages > 1){
>      for ($i=1;$i<=$total_pages;$i++){
>         if ($page == $i){
>            echo $page . " | ";
>         }else{
>            echo "<a href='xvr_web10901.php?page=" . $i . "'>" . $i . "</a> |
> ";
>         }
>      }
>  }
>  ?> 
>  
>  </body>
>  </html>
>  
>  I am almost new to PHP (1 day working with it, so maybe newbie is the rigth
> word)....
>  
>  Thanks in advance.
>  
>  -- 
>  L.A. Jenaro Centeno Gómez
> Alimentos La Concordia, S.A. de C.V.
> Loma de Prados No. 1332
> Col. La Marimba
> Lagos de Moreno, Jal.
> C.P. 47470
> Tel.- 01 474 741 92 00 Ext. 9280
> 
> 
> La informacion contenida en este mensaje y sus anexos es de caracter privado
> y confidencial y para el uso exclusivo de la persona o institucion a la cual
> ha sido enviado y para otros autorizados para recibirlo, por lo que no podra
> distribuirse sin la autorizacion expresa del remitente. Si usted no es el
> destinatario a quien este mensaje fue dirigido o si no es un empleado
> responsable del envio de este mensaje al destinatario, se hace de su
> conocimiento que cualquier revision, diseminacion, distribucion, copia u
> otro uso o acto realizado con base en o relacionado con el contenido de este
> mensaje y sus anexos está estrictamente prohibida y puede ser ilegal.
> Asimismo, el presente mensaje no representa la manifestacion del
> consentimiento de ninguna de las partes, por lo que no genera derecho u
> obligación alguna para ambas sino hasta que sus representantes legales asi
> lo manifiesten por escrito. Si usted ha recibido este comunicado y sus
> anexos por error, le soli
> citamos lo notifique inmediatamente al remitente respondiendo a este correo
> y borre el presente y sus anexos de su sistema sin conservar copia de los
> mismos. Se suprimieron acentos y caracteres especiales para legibilidad del
> mismo. Gracias. Alimentos La Concordia, S.A. de C.V.
> 
> The information contained in this message and its attachments is private and
> confidential and is intended solely for the use of the individual or entity
> to whom it is addressed and others who are authorized to receive it;
> therefore, its distribution cannot be possible without authorization from
> the sender. If you are not the intended recipient or an employee responsible
> for delivering this message to the intended recipient, you are hereby
> notified that any revision, dissemination, distribution, copying or other
> use or action based upon or relative to the information contained in this
> message and its attachments is strictly prohibited and may be unlawful. You
> are also informed that the contents of this message shall not be considered
> as an agreement between the parties and shall not bind any of them until
> their attorneys decide to do so in writing. If you have received this
> message and its attachments by error, please immediately notify the sender
> by replying to this mess
> age and deleting it from your system without keeping a copy. Thank you.
> Alimentos La Concordia, S.A. de C.V.
> 
>  
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
Pablo M. Rivas. http://www.pmrivas.com http://www.r3soft.com.ar
-----------------------------------------------------------

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux