[Resolvido] paginação
queridos, não consigo coloar este código em minha página (paginação)
<?php
$pg = $_GET['pg'];
if(isset($pg)){
$pg = $pg;
}else{
$pg = 1;
}
$quantidade = 5;
$inicio = ($pg*$quantidade) - $quantidade;
$sql = mysql_query("SELECT * FROM tb_caes ORDER BY ANO_nasc_cao LIMIT $inicio, $quantidade");
while($linha = mysql_fetch_array($sql)){
$ano = $linha[' ANO_nasc_cao '];
echo "$ano<br>";
}
$sql_2 = mysql_query("SELECT * FROM tb_caes");
$total_registros = mysql_num_rows($sql_2);
$paginas = ceil($total_registros/$quantidade);
$links = 1;
echo "<a href='resultados.php?pg=1'>primeira página </a> ";
for($i = $pg-$links; $i <= $pg-1; $i++){
if($i<=0){
}else{
echo " <a href=' resultados.php?pg=".$i."'>".$i."</a> ";
}
}
echo "<a href=#>$pg</a>";
for($i = $pg+1; $i <= $pg+$links; $i++){
if($i>$paginas){
}else{
echo " <a href=' resultados.php?pg=".$i."'>".$i."</a> ";
}
}
echo " <a href=' resultados.php?pg=".$paginas."'>ultima página </a> ";
?>
// esse é meu código
<?php require_once('Connections/conexao.php'); ?>
<?php
// RESULTADO DO MEU RECORDSET
//MX Widgets3 include
require_once('includes/wdg/WDG.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$t_busca_r_gral = "-1";
if (isset($_GET['t_busca'])) {
$t_busca_r_gral = $_GET['t_busca'];
}
mysql_select_db($database_conexao, $conexao);
$query_r_gral = sprintf("SELECT * FROM tb_caes WHERE (raca_cao LIKE %s or nome_cao LIKE %s) and LIBERAR_ANUN_cao ='1' ORDER BY ANO_nasc_cao DESC", GetSQLValueString("%" . $t_busca_r_gral . "%", "text"),GetSQLValueString("%" . $t_busca_r_gral . "%", "text"));
$r_gral = mysql_query($query_r_gral, $conexao) or die(mysql_error());
$row_r_gral = mysql_fetch_assoc($r_gral);
$totalRows_r_gral = mysql_num_rows($r_gral);
?>
// tenho uma tabela onde exibe os dados
por favor me ajudem muito obrigada
BRUNA
Discussão (13)
Carregando comentários...