Forum Moderators: coopster

Message Too Old, No Replies

Pagination .- stuck on page 1

         

MersauX

1:51 pm on Sep 25, 2006 (gmt 0)

10+ Year Member



Hello everyone. This is my first post here and it's a problem right away. I set up EasyPHP on my computer and I wrote this piece of code so I can paginate the items contained in the database. It all looks fine and well, but when I try to go to the next page i.e. 2,3,4 in the address bar it says I'm on that page, but nothing happens on the page, I still see the first page with its enteries.

I hope you can help me with this. Thanks in advance.

function all_news ($num) {

global $news_table,$page;

$query = mysql_query("SELECT * FROM $news_table ORDER BY id DESC");
$queryrows = mysql_num_rows($query);

if ($queryrows == 0) {

print "There are no item in the database...";

}

else {

if ($page == 0) $page = 1;

$numpage = $num; //Items on page
$total = $queryrows; //Total items
$totalpages = intval($total/$numpage) + 1; //Total pages

$from = (($page-1) * $numpage);
$to = (($page * $numpage) < $total? ($page * $numpage) : $total);

print "<div class=\"pages\">";
print "<ul>";
print "<li>Page: </li>";

if ($page>1) {
print "<li><a href=\"?action=allnews&page=".($page-1)."\">&lt;&lt;Previous</a> </li>";
}
for ($i=1; $i<=$totalpages; $i++) {

if ($i == $page) {
print "<li><b>[$i] </b></li>";
}

else {
print "<li><a href=\"?action=allnews&page=$i\">$i</a> </li>";
}
}

if ($page<=$totalpages-1) {
print "<li><a href=\"?action=allnews&page=".($page+1)."\">Next&gt;&gt;</a></li>";
}

print "</ul></div>";

for($from; $from<$to; $from++) {

$get_id = mysql_result($query, $from, 0);
$get_naslov = mysql_result($query, $from, 1);
$get_uvod = mysql_result($query, $from, 2);
$get_tekst = mysql_result($query, $from, 3);
$get_kategorija = mysql_result($query, $from, 4);
$get_datum = mysql_result($query, $from, 5);

if ($get_kategorija == 1) $get_kat = "News";
if ($get_kategorija == 2) $get_kat = "Interviews";

print "<div class=\"allnews\"><span class=\"naslov\">&raquo; <a href=\"?action=editnews&id=$get_id\">";
if($get_naslov == "") {
print "WARNING - No title";
}
else {
print "$get_naslov";
}
print "</a></span><br><span class=\"datum\">Broj: $get_id ¦ Datum: $get_datum ¦ Kategorija: $get_kat ¦
<b>[ </b><a href=\"?submit=deletenews&id=$get_id\">Delete</a><b> ]</b></span></div>";
}
print "<div class=\"pages\">";
print "<ul>";
print "<li>Page: </li>";

if ($page>1) {
print "<li><a href=\"?action=allnews&page=".($page-1)."\">&lt;&lt;Previous</a> </li> ";
}

for ($i=1; $i<=($totalpages); $i++) {
if ($i == $page) {
print "<li><b>[$i] </b></li>";
}

else {
print "<li><a href=\"?action=allnews&page=$i\">$i</a> </li>";
}
}

if ($page<=$totalpages-1) {
print "<li><a href=\"?action=allnews&page=".($page+1)."\">Next&gt;&gt;</a></li>";
}

print "</ul></div>";

}
}

MersauX

6:19 pm on Sep 25, 2006 (gmt 0)

10+ Year Member



Oh oh, I've got it, I resolved the problem, sorry for opening the topic, I was missing $page = $_GET['page']; on top of the script.

eelixduppy

7:19 pm on Sep 25, 2006 (gmt 0)



Glad you found the error, MersauX. By the way, welcome to WebmasterWorld! ;)