paginareanunturi.php
Cod: Selectaţi tot
<?php
include "connect_to_mysql.php";
$sql = mysql_query("SELECT id, titluanunt, sunteti FROM anunturi ORDER BY id ASC");
$nr = mysql_num_rows($sql);
if (isset($_GET['pn'])) {
$pn = preg_replace('#[^0-9]#i', '', $_GET['pn']);
} else {
$pn = 1;
}
$itemsPerPage = 2;
$lastPage = ceil($nr / $itemsPerPage);
if ($pn < 1) {
$pn = 1;
} else if ($pn > $lastPage) {
$pn = $lastPage;
}
$centerPages = "";
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;
if ($pn == 1) {
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
} else if ($pn == $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
} else if ($pn > 2 && $pn < ($lastPage - 1)) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> ';
} else if ($pn > 1 && $pn < $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $pn . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> ';
}
$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
$sql2 = mysql_query("SELECT id, titluanunt, textanunt, pret, moneda, sunteti FROM anunturi ORDER BY id ASC $limit");
////////////////////////////////////////////////////////////////////////////////////////////////////////
$paginationDisplay = "";
if ($lastPage != "1"){
$paginationDisplay .= 'Pagina <strong>' . $pn . '</strong> din ' . $lastPage. ' ';
if ($pn != 1) {
$previous = $pn - 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Precedenta</a> ';
}
$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
if ($pn != $lastPage) {
$nextPage = $pn + 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Urmatoarea</a> ';
}
}
$outputList = '';
$cat_anunt = $_GET['id'];
$sql2 = mysql_query("SELECT id, titluanunt, textanunt, sunteti, pret, categorie FROM anunturi WHERE categorie='".$cat_anunt."' ORDER BY RAND() LIMIT 4")or die(mysql_error());
while($row = mysql_fetch_array($sql2)){
$id = $row["id"];
$titluanunt = $row["titluanunt"];
$textanunt = $row["textanunt"];
$pret = $row["pret"];
$moneda = $row["moneda"];
$sunteti = $row["sunteti"];
$user_pic = "<img src=\"imagini/image.jpg\" width=\"170px\" height=\"100px\" border=\"0\" />";
$textanuntCut = substr($textanunt, 0, 150);
$titluanuntCut = substr($titluanunt, 0, 87);
$outputList .=
'<table width="100%" height="1%" border="0">
<tr>
<td valign="top"><table width="100%" border="0" bordercolor="#CC0000" bgcolor="#CC0000">
<tr>
<td width="74%" bordercolor="#CC0000" bgcolor="#CC0000"><span class="style2"><a href="anunt.php?id=' . $id . '" target="_blank"><font color="white"><b>' . $titluanuntCut . '</b></font></a></span></td>
<td width="14%" bgcolor="#CC0000"><span class="style1"><a><span class="style2"><font color="white">' . $pret . ' ' . $moneda . '</font></span></a></span></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td width="20%"><div style="width="100" height="60" overflow:hidden;"><a href="anunt.php?id=' . $id . '" target="_blank">' . $user_pic . '</a> </td>
<td width="80%" valign="top">' . $textanuntCut . ' </td>
</tr>
</table></td>
</tr>
</table>
';
}
$outputList .= ' </tr>
</table> ';
?>
acum...problema e urmatoarea...
cand intru in cat.php imi apare prima pagina...fara nici o problema dar cand dau la paginare urmatoarea pagina imi da eroare ca nu e definit id pe care il am $cat_anunt = $_GET['id'];
cum sa fac sa nu imi mai apara asa?