Problema afisare in script paginare
Scris: Mar Noi 06, 2012
Salut,
Am fisieru index.php
fisierul function.php
fisierul db.php
Acesta este un script de paginare luat de pe net (nu mai stiu exact de unde). Problema este ca atunci cand gaseste 3-4 rezultate e ok, dar daca gaseste mai multe imi afiseaza un spatiu in josul site-ului si nu stiu de unde pana unde.
Un exemplu cum afiseaza este aici, adresa URL:
evi-anunturi.net/categorie.php?id=Telefoane&subcategorie=Telefoane%20mobile
Stima
Am fisieru index.php
Cod: Selectaţi tot
<?php
include_once ('db.php');
include_once ('function.php');
$xcategorie = $_GET['id'];
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 10;
$startpoint = ($page * $limit) - $limit;
$statement = "`anunturi` where `categorie` = '" . $xcategorie . "'";
?>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="css/pagination.css" rel="stylesheet" type="text/css" />
<link href="css/B_blue.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.records {
width: 700px;
height:2325;
margin: 5px;
padding:2px 5px;
border:1px solid #B6B6B6;
}
.record {
color: #474747;
margin: 20px 0;
padding: 3px 5px;
background:#E6E6E6;
border: 1px solid #B6B6B6;
cursor: pointer;
letter-spacing: 2px;
}
.round {
-moz-border-radius:8px;
-khtml-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius:8px;
}
p.createdBy{
padding:5px;
width: 510px;
font-size:15px;
text-align:center;
}
p.createdBy a {color: #666666;text-decoration: none;}
</style>
<div class="records round">
<?php
//show records
$query = mysql_query("SELECT * FROM {$statement} LIMIT {$startpoint} , {$limit}");
while ($row = mysql_fetch_assoc($query)) {
$id = $row["id"];
$email_la_pag_anunt = $row["email"];
$vip = $row["vip"];
$textanunt = $row["textanunt"];
$categorie = $row["categorie"];
$titluanunt = $row["titluanunt"];
$data_adaugari = strftime("%d-%b-%Y", strtotime($row['data_adaugari']));
$expira = strftime("%d-%b-%Y", strtotime($row['expira']));
$check_pic = "anunt/$id/poza.jpg";
$default_pic = "anunt/0/poza.jpg";
if (file_exists($check_pic)) {
$user_pic = "<img src=\"$check_pic\" width=\"167px\" height=\"150\" border=\"0\" alt=\"Listing Image\" class=\"listingimage\" />";
} else {
$user_pic = "<img src=\"$default_pic\" width=\"167px\" height=\"150\" border=\"0\" alt=\"Listing Image\" class=\"listingimage\"/>";
}
$textanunt=''.$row['textanunt'].'';
$text = ucfirst($textanunt);
$textanuntCut = substr($text, 0, 300);
$titluanunt=''.$row['titluanunt'].'';
$titlu = ucfirst($titluanunt);
$titluanuntCut = substr($titlu, 0, 11);
$pret = $row["pret"];
$moneda = $row["moneda"];
?>
<div class="record round"><?php echo '<table width="690" border="0" cellspacing="10">
<tr>
<td width="187" height="150" rowspan="2" valign="top" background="imagini/background_display_prima_pagina.JPG"><div align="center" class="style3"><a href="anunt.php?id=' . $id . '"">' . $titluanuntCut . '</a></div>
<div align="center"><a href="anunt.php?id=' . $id . '">' . $user_pic . '</a></div></td>
<td width="469" height="131" valign="top" background="imagini/background_display_prima_pagina.JPG"><div class="style3">' . $textanuntCut . '...</div></td>
</tr>
<tr>
<td height="35" valign="top" background="imagini/background_display_prima_pagina.JPG"><div align="right" class="style2"><span class="style1">Pret: ' . $pret . ' ' . $moneda . '</span></div></td>
</tr>
</table>';?></div>
<?php
}
?>
<?php
echo pagination($statement,$limit,$page);
?>
</div>
Cod: Selectaţi tot
<?php
/**
* @link: http://www.Awcore.com/dev
*/
$xcategorie = $_GET['id'];
$xsubcategorie = $_GET['subcategorie'];
function pagination($query, $per_page = 10,$page = 1, $url = '?id=. $xcategorie .&'){
$query = "SELECT COUNT(*) as `num` FROM {$query}";
$row = mysql_fetch_array(mysql_query($query));
$total = $row['num'];
$adjacents = "2";
$page = ($page == 0 ? 1 : $page);
$start = ($page - 1) * $per_page;
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total/$per_page);
$lpm1 = $lastpage - 1;
$pagination = "";
$xcategorie = $_GET['id'];
$xsubcategorie = $_GET['subcategorie'];
if($lastpage > 1)
{
$pagination .= "<ul class='pagination'>";
$pagination .= "<li class='details'>Page $page of $lastpage</li>";
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li><a class='current'>$counter</a></li>";
else
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$counter'>$counter</a></li>";
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<li><a class='current'>$counter</a></li>";
else
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$counter'>$counter</a></li>";
}
$pagination.= "<li class='dot'>...</li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$lpm1'>$lpm1</a></li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$lastpage'>$lastpage</a></li>";
}
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=1'>1</a></li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=2'>2</a></li>";
$pagination.= "<li class='dot'>...</li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<li><a class='current'>$counter</a></li>";
else
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$counter'>$counter</a></li>";
}
$pagination.= "<li class='dot'>..</li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$lpm1'>$lpm1</a></li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$lastpage'>$lastpage</a></li>";
}
else
{
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=1'>1</a></li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=2'>2</a></li>";
$pagination.= "<li class='dot'>..</li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<li><a class='current'>$counter</a></li>";
else
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$counter'>$counter</a></li>";
}
}
}
if ($page < $counter - 1){
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$next'>Urmatoarea</a></li>";
$pagination.= "<li><a href='?id=" . $xcategorie . "&subcategorie=" . $xsubcategorie . "&page=$lastpage'>Ultima</a></li>";
}else{
$pagination.= "<li><a class='current'>Urmatoarea</a></li>";
$pagination.= "<li><a class='current'>Ultima</a></li>";
}
$pagination.= "</ul>\n";
}
return $pagination;
}
?>
Cod: Selectaţi tot
<?php
/**
* @link: http://www.Awcore.com/dev
*/
$db = @mysql_connect('localhost', 'rootr', '') or die(mysql_error());
@mysql_select_db('test', $db) or die(mysql_error());
?>
Un exemplu cum afiseaza este aici, adresa URL:
evi-anunturi.net/categorie.php?id=Telefoane&subcategorie=Telefoane%20mobile
Stima