Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   PHP (https://www.clubdelphi.com/foros/forumdisplay.php?f=15)
-   -   mostrar 15 registros por paginas (https://www.clubdelphi.com/foros/showthread.php?t=14834)

alachaise 01-10-2004 16:01:25

mostrar 15 registros por paginas
 
tengo una una una pagina que me muestar cuators campos como hago para que se muestren 15 por paginas



Código:

 
 
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
          <title>Title here!</title>
<meta http-equiv="" content="text/html; charset=iso-8859-1"></head>
<body text="#0000FF">
<body bgcolor="#cccccc">
<br>
<table align='center' border='0' bordercolor="#FFffff" >
<tr bgcolor='#666666'><td bgcolor="#CCCCCC">
<p align="center"><a href='altatema.php'><font size='4' color='#0000FF'>Agregar Temas a Provincias</font> </a></p>
 </td></tr>
<?php
if ($abierto = mysql_connect ("localhost","root","")){
$leer = "SELECT id,tema,autor,hijos,fecha FROM TEMAS  WHERE tema<>' '";
$datos = mysql_db_query ("basedatosuccm",$leer);
print("<center><table width='50%' border='0'></center>");
print ("<tr bgcolor='#000000'><td align='center'><font size='4' color='#ffffff'>Provincia</font></td><td align='center'><font size='4' color='#ffffff'>Tema</font></td><td align='center'>
<font size='4' color='#ffffff'>Mensajes</font></td><td align='center'><font size='4' color='#ffffff'>Ult.Act.</font></td>");
while ($fila = mysql_fetch_array ($datos)) {
print ("<tr><td bgcolor='#ffffff' align='center'><a href='listahijos.php?var=$fila[0]'>".$fila[1]."</a></td><td bgcolor='#ffffff' align='center'>".$fila[2]."</td><td bgcolor='#ffffff' align='center'>".$fila[3].
"</td><td bgcolor='#ffffff' align='center'>".$fila[4]."</td></tr>");
}
print ("</table>");
} else {
print ("No se puede conectar. Intente nuevamente");
}
?>
 
<hr>
</body>
</html>


roman 01-10-2004 21:39:14

Si te refieres a cómo paginar los resultados de una consulta (mostrar
n registros por cada página) te puede servir este artículo que habla
de cómo hacerlo con php y mysql:

http://tinyurl.com/54oha

// Saludos

Emilio 03-10-2004 12:47:10

Con este ya van 3 hilos que abres con el mismo tema. En http://www.clubdelphi.com/foros/showthread.php?t=14597 tienes una respuesta, si no entiendes la respuesta, comentalo en el mismo hilo pero no sigas abriendo nuevos hilos para lo mismo que ya van 3.

Tangela 19-10-2004 22:31:39

Paginator
 
En esta dirección hay un script llamado paginator que va de maravilla. Mira a ver si te sirve.
http://jpinedo.webcindario.com
Un saludo

Emilio 21-10-2004 14:48:17

Aquí tienes otro ejemplo, además de usar el típico "navigator" también responde a las teclas página arriba y abajo, si le pegas un vistazo al código fuente verás también un sencillo sistema para generar menús emergentes en el lado del cliente.
http://www.clubdelphi.net/indexclub.php

roman 21-10-2004 16:06:22

Hola Emilio,

Está muy bonito tu ejemplo pero, ¿será posible que nos muestres el código php? :rolleyes:

// Saludos

kalimero 22-10-2004 13:04:48

Hola a todos.

Estoy intentando hacer lo mismo con Firebird, pero no doy con la sintaxis correcta de la 'Select'. ¿Podriais ayudarme?

Gracias de antemano

Emilio 22-10-2004 16:03:15

Aquí está el código, lo he comentado bastante, pero si hay alguna duda... pues para eso está el foro, para preguntar ;)
Código PHP:

<?
    
// Conectamos a MySQL.
    
mysql_connect("Host""User""Pass") or die ("La cagamos, esto no conecta.");
    
mysql_select_db("BaseDeDatos") or die ("Cobarde, andesta la base de datos.");
    if (
$tecla=="") { $tecla="0"; }
 
    
// Vemos que parámetros hemos recibido para construir la sentencia sql.
    
if ( $tipo ) { $where[]="(forumid =$tipo)"; }
    
$where[]="( forumid<>32 )";
    if ( 
$scan=="" ) { $clausula =" WHERE "; } else { $clausula " AND "; }
    
$where implode(" AND ",$where);
    
$where $clausula.$where;
    
// Fin construcción de la sentencia por ahora, la continuamos más abajo.
 
    // Si tenemos algo en $scan
    
if ( $scan!="" ) {
        
$scan StrToUpper$scan );
        
$ascan split" ",$scan );
        for (
$i 0$i count($ascan); $i++) {
            if (
$i==0) {
                
$sql ="SELECT * FROM thread
                where (title like '%"
.$ascan[0]."%' or postusername like '%".$ascan[0]."%' or lastposter like '%".$ascan[0]."%')";
                
$result mysql_query($sql);
                while (
$row mysql_fetch_array($result)) {
                    
$codigos[] = $row["threadid"];
                    
$encontrado true;
                }
                if ( 
$encontrado ) { $codigos implode(",",$codigos ); }
            }
            if (
$i!=0) {
                
$sql .= " AND threadid IN ( $codigos ) AND (title like '%$ascan[$i]%' or postusername like '%$ascan[$i]%')";
                
$sql .= $where;
            }
        }
    }
    else {
        
$sql ="SELECT * FROM thread ";
    }
    
// Fin control scan
 
    // Le añadimos lo que tenga el where.
    
$sql .= $where;
 
    
// Contamos cuantos registros tiene la consulta. Reemplazamos el "SELECT *" por el "SELECT COUNT(*) as registros"
    
$result_count mysql_querystr_replace "SELECT *""SELECT COUNT(*) as registros"$sql) );
    
$line         mysql_fetch_array($result_count);
    
$cuantos     $line['registros'];
 
    
// Seteamos si no lo está, la variable $cadapagina
    
if(isset($cadapagina)) {
        
// si está seteada, comprobamos que es un entero y que además sea mayor o igual a 25
        
$cadapagina max(25$cadapagina);
    }
    else {
        
// si no está seteada le asignamos 25 a piñon.
        
$cadapagina 25;
    }
 
    
// Permitimos un máximo de 100 registros por página
    
$cadapagina min(100$cadapagina);
 
    
// Vemos de cuantas páginas se compone el resultado de la consulta
    
$ultima ceil($cuantos $cadapagina);
 
    
// Seteamos si no lo está la variable $pagina
    
$pagina = @(int)$pagina;
    if ( 
$pagina $pagina 1;
    if ( 
$pagina $ultima $pagina $ultima;
 
    
// Terminamos de construir la sentencia que mostraremos.
    
$ini = (($pagina $cadapagina) - $cadapagina);
 
    
// Construimos el ordenamiento de la sentencia.
    
if ($orden !="") { $ORDENAMOS ' ORDER BY '.$orden; } else { $ORDENAMOS ' ORDER BY threadid DESC'; }
 
    
// Hacemos el LIMIT de los registros que vamos a mostrar.
    
$sql $sql.$ORDENAMOS." LIMIT ".$ini.",".$cadapagina;
    
$sql_impresion $sql;
 
    
// Disponemos el resultado para el while que ejecuta el mysql_fetch_array.
    
$result mysql_query$sql );
 
    
// creamos los enlaces a la siguiente página y a la última.
    
if ($pagina == $ultima) {
        
// ya estamos en la última página, no habrá link
        
$siguiente "<img src='/images/siguienteoff.gif' width='20' height='20' border='0'>";
        
$final "<img src='/images/ultimooff.gif' width='20' height='20' border='0'>";
    }
    else {
        
// página distinta de la última, sí habrá link
        
$sig $pagina 1;
        
$siguiente "<a href='$PHP_SELF?scan=$scan&tecla=34&orden=$orden&direccion=$direccion&pagina=$sig&cadapagina=$cadapagina&tipo=$tipo' title='Siguiente'><img src='/images/siguiente.gif' width='20' height='20' border='0'></a>";
        
$final     "<a href='$PHP_SELF?scan=$scan&tecla=35&orden=$orden&direccion=$direccion&pagina=$ultima&cadapagina=$cadapagina&tipo=$tipo' title='Final'><img src='/images/ultimo.gif' width='20' height='20' border='0'></a>";
    }
 
    
// y ahora el enlace a las páginas anterior y primera:
    
if ($pagina == 1) {
        
// ya estamos en la primera página, no habrá link
        
$anterior "<img src='/images/anterioroff.gif' width='20' height='20' border='0'>";
        
$principio "<img src='/images/primerooff.gif' width='20' height='20' border='0'>";
    }
    else {
        
// página distinta de la primera, sí habrá link
        
$ant $pagina 1;
        
$anterior "<a href='$PHP_SELF?scan=$scan&tecla=33&orden=$orden&direccion=$direccion&pagina=$ant&cadapagina=$cadapagina&tipo=$tipo' title='Anterior'><img src='/images/anterior.gif' width='20' height='20' border='0'></a>";
        
$principio "<a href='$PHP_SELF?scan=$scan&tecla=36&orden=$orden&direccion=$direccion&pagina=1&cadapagina=$cadapagina&tipo=$tipo' title='Principio'><img src='/images/primero.gif' width='20' height='20' border='0'></a>";
    }
    
// Fin crear enlaces
?>
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><HEAD><TITLE>Club Delphi</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<link REL="stylesheet" TYPE="text/css" HREF="/club.css">
</HEAD>
 
<style type="text/css">
<!--
body {
    margin-left:    0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
form {
    margin-left:    0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
.menupop {
    text-indent:    3px;
    font:     menu;
    background: ButtonFace;
    font-weight:    bold;
}
.menupop thead td {
    backgroundColor:#006699;
    textAlign: center;
    color:     #FFFFFF;
}
.menupop td {
    border:     1px solid;
    border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
    padding:    2px 2px;
    cursor:     hand;
}
</style>
 
<script>
var
TDClick ='<? echo $orden?>';
 
function ordenar(campo) {
    var columnas=cabeceras.getElementsByTagName("TD");
    for (i=0;i<columnas.length-1;i++) columnas.item(i).style.backgroundColor="buttonface"
    document.form.orden.value=campo;
    validar(13);
}
document.onkeydown = keyDown
 
function keyDown() {
    var keycode = event.keyCode
    // 13 Tecla enter
    // 27 Tecla Escape
    // 33 Tecla Página arriba
    // 34 Tecla Página abajo
    // 35 Tecla Fin
    // 36 Tecla Inicio
    if ((keycode==13) || (keycode==33) || (keycode==34) || (keycode==35) || (keycode==36)) {
        validar( keycode );
    }
}
 
function validar(tecla) {
    if (tecla==34) { // Página abajo.
        location.href='<? echo "[url="http://$server_name/indexclub.php?scan=$scan&tecla=34&orden=$orden&direccion=$direccion&pagina=$sig&cadapagina=$cadapagina&tipo=$tipo"]http://$SERVER_NAME/indexclub.php?scan=$scan&tecla=34&orden=$orden&direccion=$direccion&pagina=$sig&cadapagina=$cadapagina&tipo=$tipo[/url]"; ?>';
    }
    if (tecla==33) { // Página arriba.
        location.href='<? echo "[url="http://$server_name/indexclub.php?scan=$scan&tecla=33&orden=$orden&direccion=$direccion&pagina=$ant&cadapagina=$cadapagina&tipo=$tipo"]http://$SERVER_NAME/indexclub.php?scan=$scan&tecla=33&orden=$orden&direccion=$direccion&pagina=$ant&cadapagina=$cadapagina&tipo=$tipo[/url]"; ?>';
    }
    if (tecla==13) {
        document.form.tecla.value=tecla;
        document.form.submit();
    }
}
 
function oculta() {
    document.getElementById("divmenu").style.visibility = document.form.xmenu.value;
    document.form.xmenu.value='hidden'
}
 
function menu(x,y,registro) {
    document.getElementById("divmenu").style.left = x;
    document.getElementById("divmenu").style.top = y;
    document.getElementById("divmenu").style.visibility='visible';
 
    // Seteamos el registro en una nueva variable del divmenu.
    document.getElementById("divmenu").registro = registro;
 
    // Creamos el título del divmenu
    document.getElementById("texto").childNodes[0].nodeValue="Registro: "+registro;
}
 
document.onclick=oculta;
 
</script>
 
<BODY leftMargin="0" topMargin="0" marginheight="0 marginwidth="0" onload="document.form.scan.focus()" onContextMenu="return false">
<? include("club_cabecera.inc.php"); ?>
<TABLE class=top cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR>
    <TD width=140 align="left" vAlign=top>
     <? include("club_izquierda.inc.php"); ?>
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <td>&nbsp;</td>
        </tr>
     </table>     </TD>
    <TD height=440 align=left vAlign=top>
     <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#000000" align="center">
        <form name="form" method="post" action="indexclub.php">
        <tr>
         <td width="250" bgcolor="#7788aa" class="subheadb"> <font color="#FFFFFF"><B>Scan</B></font>
            <input name="scan" type="text" class="textarea" value="<? echo $scan?>" size="27">
             </td>
            <td width="160" bgcolor="#7788aa" class="subheadb"><B><font color="#FFFFFF">Registros
             por P&aacute;g.</font></B>
             <input name="cadapagina" type="text" class="textarea" value="<? echo $cadapagina?>" size="3" maxlength="3">
            </td>
         <td class="subheadb" bgcolor="#7788aa"><div align="center"><B><font color="#FFFFFF">Buscar
                en </font></B>
                <select name="tipo" onChange="validar(13)" style="color: #FFFFFF; background-color: #006699; width: 200px; font-family: Verdana, Arial, Helvetica; font-size: 11px; font-weight=bold">
                <option value='0' selected>Todos los foros</option>
                <?
                $sql_foros 
"SELECT * FROM forum WHERE forumid<>32 and parentid > 0";
                
$fresult mysql_query($sql_foros);
                while (
$frow mysql_fetch_array($fresult)) {
                if ( 
$tipo== $frow["forumid"] ) { $seleccionado " selected";} else { $seleccionado =""; }
                
?>
                    <option value='<? echo $frow["forumid"]; ?><? echo $seleccionado?>><? echo $frow["title"?></option>
                <?
                
}
                
?>
                </select>
                        <input name="tecla" type="hidden" id="tecla">
                        <input type="hidden" name="orden">
                <input name="xmenu" type="hidden" id="xmenu" value="hidden">
             </div></td>
            <td width="100" align="center" valign="middle" class="subhead">
             <? echo $principio?><? echo $anterior?><? echo $siguiente?><? echo $final?>
             </td>
        </tr>
        </form>
     </table>
     <div id="cabeceras">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="cabecera">
         <tr><td width="25"><div align="center"><strong>M</strong></div></td>
            <td width="60" title="Ordenar por ID" style="cursor:hand" onclick="ordenar('threadid'); this.style.backgroundColor='#7788AA'; TDClick='thread'" OnMouseOver="if (TDClick !='threadid') {this.style.backgroundColor='#7788AA'}" OnMouseOut=" if (TDClick !='threadid') this.style.backgroundColor='buttonface'"; ><B>ID</B></td>
 
            <td            title="Ordenar por Título" style="cursor:hand" onclick="ordenar('title'); this.style.backgroundColor='#7788AA'; TDClick='title'" OnMouseOver="if (TDClick !='title') {this.style.backgroundColor='#7788AA'}" OnMouseOut=" if (TDClick !='title') this.style.backgroundColor='buttonface'"; ><B>Título</B></td>
            <td width="125" title="Ordenar por Iniciado por..." style="cursor:hand" onclick="ordenar('postusername'); this.style.backgroundColor='#7788AA'; TDClick='postusername'" OnMouseOver="if (TDClick !='postusername') {this.style.backgroundColor='#7788AA'}" OnMouseOut=" if (TDClick !='postusername') this.style.backgroundColor='buttonface'"; ><B>Iniciado
             por...</B></td>
            <td width="125" title="Ordenar por Último user" style="cursor:hand" onclick="ordenar('lastposter'); this.style.backgroundColor='#7788AA'; TDClick='lastposter'" OnMouseOver="if (TDClick !='lastposter') {this.style.backgroundColor='#7788AA'}" OnMouseOut=" if (TDClick !='lastposter') this.style.backgroundColor='buttonface'"; ><B>Último
             user</B></td>
            <td width="50" ><strong>Resp</strong></td>
         </tr>
        </table>
     </div>
 
 
     <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#000000" align="center">
        <tr>
         <td valign="top">
            <?
            
while ($row mysql_fetch_array($result)) {
                
$textolibre trim($row["TEXTOLIBRE"]) ;
                
$textolibre ereg_replace("[^A-Za-z0-9áéíóúÁÉÍÓÚñÑ [url="file://n//r/n//r"]\\n\\r\n\\r[/url]]", "<br>", $textolibre);
                
$textolibre preg_replace("/(\r\n|\n|\r)/"""$textolibre);
                
//if ($color=="#CCCCCC" ){ $color="#DDDDDD";     }else {if ($color=="#DDDDDD" ){ $color="#DDDDDC";     } else { $color="#CCCCCC"; }    }
                
?>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#DFDFDF">
                <tr class="lineas"
                    onContextMenu="menu(event.clientX,event.clientY,<? echo $row["threadid"]; ?> )"
                        OnMouseOver="this.style.background='#7788aa'; this.style.color='white'; this.style.cursor='hand';";
                        OnMouseOut="this.style.background=''; this.style.color='black';">
                    <td id="imgmenu" width="25" onclick="document.form.xmenu.value='visible'; menu(event.clientX,event.clientY,<? echo $row["threadid"]; ?> )"><div align="center"><img src="/images/menu.gif" width="16" height="16" border="0"></div></td>
                    <td width='60'> <? echo $row["threadid"]; ?>&nbsp;</td>
                    <td> <? echo $row["title"]; ?>&nbsp;</td>
                    <td width='125'> <? echo $row["postusername"]; ?>&nbsp;</td>
                    <td width="125"><? echo $row["lastposter"]; ?>&nbsp;</td>
                    <td width="50"><? echo $row["replycount"]; ?></td>
                </tr>
                </table>
                <?
            
}
            
?>
         </td>
        </tr>
     </table>
     <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#000000">
        <tr>
         <td valign="middle" bgcolor="#7788aa" class="subheadb"><div align="center"><font color="#FFFFFF"><b>Encontrados
             <? echo $cuantos?> registros, mostrando p&aacute;gina <? echo $pagina?>
             de <? echo $ultima?></b></font> </div>
            <div align="center"></div></td>
        </tr>
     </table> </TD>
</TR>
</TABLE>
<TABLE class=top cellSpacing=0 cellPadding=5 width="100%" border=0>
<TR>
    <TD>Jander Clander</TD>
    <TD vAlign=top align=right>El foot de la peich..</TD>
</TR>
</TABLE>
<div id="divmenu" style="visibility:hidden; position:absolute; left:0px; top:0px">
<table width="200" cellpadding="5" cellspacing="1" class="menupop">
    <tr bgcolor="#006699" style="text-align:center; color:white; font-weight:bold" >
            <td><span id="texto">&nbsp;</span></td>
        </tr>
        <tr
        onMouseOver="this.style.backgroundColor='highlight';this.style.color='white'"
        onMouseOut="this.style.backgroundColor='ButtonFace';this.style.color='black'"
        onClick="java_script_:ventana('temp.php?id='+document.getElementById('divmenu').registro,'',600,400,true)"
    >
            <td>Nuevo registro</td>
        </tr>
    <tr
        onMouseOver="this.style.backgroundColor='highlight';this.style.color='white'"
        onMouseOut="this.style.backgroundColor='ButtonFace';this.style.color='black'"
        onClick="java_script_:ventana('temp.php?id='+document.getElementById('divmenu').registro,'',600,400,true)"
    >
            <td>Modificar registro</td>
        </tr>
    <tr
        onMouseOver="this.style.backgroundColor='highlight';this.style.color='white'"
        onMouseOut="this.style.backgroundColor='ButtonFace';this.style.color='black'"
        onClick="java_script_:ventana('temp.php?id='+document.getElementById('divmenu').registro,'',600,400,true)"
    >
            <td>Eliminar registro</td>
        </tr>
    <tr
        onMouseOver="this.style.backgroundColor='highlight';this.style.color='white'"
        onMouseOut="this.style.backgroundColor='ButtonFace';this.style.color='black'"
        onClick="java_script_:ventana('temp.php?id='+document.getElementById('divmenu').registro,'',600,400,true)"
    >
            <td>Subir un fichero</td>
        </tr>
    <tr
        onMouseOver="this.style.backgroundColor='highlight';this.style.color='white'"
        onMouseOut="this.style.backgroundColor='ButtonFace';this.style.color='black'"
        onClick="java_script_:ventana('temp.php?id='+document.getElementById('divmenu').registro,'',600,400,true)"
    >
            <td>Cualquier otra gaita</td>
        </tr>
 
</table>
</div>
</BODY></HTML>



La franja horaria es GMT +2. Ahora son las 06:28:52.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi