Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa Noite, acho que estou postando no local errado, mais sou novo aqui no fórum e gostaria da ajuda de alguém para criar uma paginação numa agenda de eventos do meu site.
Há 3 dias tenho vistos diversos vídeos, porém ainda não consegui fazer a mesma funcionar.
Código:
<!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](http://www.w3.org/1999/xhtml)">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Balada Gold - Agenda</title>
<style type="text/css">font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #F4F4F4;
}background-color: #FFFFFF;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color:#666666;
text-decoration:none;
}
.style2 {color: #666666;
font-weight: bold;
font-family: Tahoma, Geneva, sans-serif;.style3 {
color: #666666;
font-weight: bold;
font-family: Tahoma, Geneva, sans-serif;
font-size: 12px;
}.style9 {
font-family: "trebuchet MS", Tahoma, Arial;
color: #CC0000;
font-size: 12px;
}#agenda{width:415px; background:#969; height:150px;}
#agenda .imagem{width:120px; height:120px; background:#039; float:left;}
#agenda .descricao{width:290px; height:120px; background:#660; float:right;}
-->
</style>
<script>
function abrir(dochtml, largura, altura, scroll) {
if(navigator.appName == "Netscape") {
sec = window.open(dochtml,'_blank','scrollbars=' + scroll + ',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,copyhistory=no,height='+ altura +',width='+ largura +',top=51,left=5');
window.sec.focus();
}window.open(dochtml,'_blank','scrollbars=' + scroll + ',toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,copyhistory=no,height=' + altura + ',width=' + largura + ',top=51,left=5');
}
}
</script>
</head>
<body>include("conexao.php");
$sql = mysql_query("SELECT * FROM eventos ORDER BY mes , dia asc");
$contar = mysql_num_rows($sql);
if($contar < 1) {
echo "<font size=1 face=veredana>Não existe nenhum evento cadastrado atualmente!</font>";?>
</td>
</tr>
<tr>
<td>
<tr>
<td width="463" height="156">
<table width="414" border="0" cellpadding="2" cellspacing="2" bgcolor="#FFFFFF">
<tr>
<td width="87%" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div>
<table width="89%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="29%" height="104" align="left" valign="top">
<div align="center"><a href="javascript:abrir('mostrar.php?evento=<? echo $mostrar['id']; ?>','540','600','no');"><img src="<? echo $mostrar['foto']; ?>" width="100" height="100" border="0"></a></div></td>
<td width="71%" valign="top"><table width="98%" border="0" cellspacing="2" cellpadding="2">
<tr class="style3">
<td colspan="2"><a href="javascript:abrir('mostrar.php?evento=<? echo $mostrar['id']; ?>','540','600','no');" class="style2"><? echo $mostrar['evento']; ?></a></td>
</tr>
<tr>
<td width="16%" class="style3"><div align="left" class="style3">Data:</div></td>
<td width="84%"><div align="left" class="style6">
<? $dia = $mostrar['dia']; $mes = $mostrar['mes']; $ano = $mostrar['ano']; echo "$dia/$mes/$ano"; ?>
</div></td>
</tr>
<tr>
<td align="right" class="style3"><div align="left" class="style6"><strong>Local:</strong></div></td>
<td><div align="left" class="style6"><? echo $mostrar['local']; ?></div></td>
</tr>
<tr>
<td height="40" colspan="2" align="left" valign="bottom" class="style3"><span class="style12"><a href="javascript:abrir('mostrar.php?evento=<? echo $mostrar['id']; ?>','540','600','no');"><img src="../imagens/saiba_mais.png" border="0" /></a></span></td> </tr>
</table></td>
</tr>
</table>
</div></td>
</tr>
</table><img src="../imagens/pontilhado.png" /></td>
</tr>
</table></td>
</tr>
<?
}
}
?>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------
Paginação que encontrei na internet:
<?php
$db = "db";
@mysql_connect("localhost", "usuario", "senha") or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($db);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paginação Avançada com PHP</title>
<link rel="stylesheet" type="text/css" href="estilo.css" />
</head>
<body>
<div class="global-div">
<?php
$pag = ($_GET['pag']);
$pag = filter_var($pag, FILTER_VALIDATE_INT);
$inicio = 0;
$limite = 1 ;
if ($pag!='')$inicio = $pag - 1;
}
$busca_total = mysql_query("SELECT COUNT(*) as total FROM eventos");
$total = mysql_fetch_array($busca_total);
$total = $total['total'];
$busca = mysql_query("SELECT * FROM eventos LIMIT $inicio, $limite");extract($texto);
echo '<h2>'.$titulo.'</h2>';
echo '<p>'. nl2br($artigo).'</p>';
}
$prox = $pag + 1;
$ant = $pag - 1;
$ultima_pag = ceil($total / $limite);
$penultima = $ultima_pag - 1;
$adjacentes = 2;
echo '<div class="paginacao">';
if ($pag>1)$paginacao = '<a href="index.php?pag='.$ant.'">anterior</a>';
}
if ($ultima_pag <= 5)$paginacao .= '<a href="index.php?pag='.$i.'">'.$i.'</a>';
}
}
}
if ($ultima_pag > 5)$paginacao .= '<a href="index.php?pag='.$i.'">'.$i.'</a>';
}
}
$paginacao .= '...';
$paginacao .= '<a href="index.php?pag='.$penultima.'">'.$penultima.'</a>';
$paginacao .= '<a href="index.php?pag='.$ultima_pag.'">'.$ultima_pag.'</a>';
}$paginacao .= '<a href="index.php?pag=1">1</a>';
$paginacao .= '<a href="index.php?pag=1">2</a> ... ';
for ($i = $pag-$adjacentes; $i<= $pag + $adjacentes; $i++)$paginacao .= '<a href="index.php?pag='.$i.'">'.$i.'</a>';
}
}
$paginacao .= '...';
$paginacao .= '<a href="index.php?pag='.$penultima.'">'.$penultima.'</a>';
$paginacao .= '<a href="index.php?pag='.$ultima_pag.'">'.$ultima_pag.'</a>';
}$paginacao .= '<a href="index.php?pag=1">1</a>';
$paginacao .= '<a href="index.php?pag=1">2</a> ... ';$paginacao .= '<a href="index.php?pag='.$i.'">'.$i.'</a>';
}
}
}
}
}
if ($prox <= $ultima_pag && $ultima_pag > 2)$paginacao .= '<a href="index.php?pag='.$prox.'">próxima »</a>';
}
echo $paginacao;
echo '</div>';
?>
</div>
</body>
</html>Carregando comentários...