Forum Moderators: coopster

Message Too Old, No Replies

Displaying Page Numbers!

how?

         

dreamcatcher

6:57 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I`m writing a little weblog script, that the user can specify how many entries he/she wants to appear on the page.

Whats the syntax for displaying page numbers? I don`t want anything fancy with "next" or "previous" links, just the page numbers. Each page number links to the relevant page except the current page, which is not displayed as a hyperlink.

Any help would be appreciated, thank you!

:)

DrDoc

7:15 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



n / x = #

n = total number of posts
x = user preference of posts/page
# = a float

Just round # up, and you get the total number of pages

100 / 10 = 10
249 / 10 = 24.9 (=25)

dreamcatcher

7:43 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help. So then how do I create hyperlinks for the page numbers? You`ll have to forgive me, I`m new to this stuff.

DrDoc

7:51 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well, you could do something like:

for($i=1; $i<=$total_pages; $i++) {
if($i!=$current_page) {
echo "<a href='path_to_script/blah.php?page=$i'>$i</a> ";
}
else {
echo "$i ";
}
}

Then, of course, you need some kind of routine in your script that displays the correct "page", or interval of posts...

How to do that entirely depends on what the rest of your script looks like.

dreamcatcher

8:02 pm on Apr 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool, thanks, I can see how that would work. I`ll give it a try. I`ll be back if I run into problems. :)

dreamcatcher

12:03 am on Apr 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No surprises that I`m back for more punishment.

I`ve been playing around with this page number thing and just can`t get it working.

I`m using the following query to display the entries on the page:

$query = "SELECT * FROM weblog ORDER BY post_id DESC LIMIT $start, 5";
$result = mysql_query($query);
$rows = mysql_num_rows($result);

Now I`m assigning $start by doing:

$start = ($current_page - 1) * 5

Then doing:

for($i=1; $i<=$pagetotal; $i++) {
if($i!=$current_page) {
echo "<a href='index.php?page=$i'>$i</a> ";
}
else {
echo "$i ";
}
}

$pagetotal being set to "5" in a config file and is the amount of entries per page.

Well, I can get page numbers with the syntax index.php?page=1 etc, but they just refresh the same page.

As you can see I`m in a complete mess and have no idea what I`m doing.

I want to see 5 entries per page with relevant page links to the next page.

Am I a lost cause or what? :) I`m new to PHP so I`m not understanding this too well.

Can anyone help me out? Thanks!

dreamcatcher

8:57 am on Apr 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its ok guys, I figured it out and its working fine. Thanks for your patience!

:)