My PHP knowledge is extremely limited so with someone saying read this wont help me much. Anyway... below should be everything one would need to assist me.

Thx in advance !

http://www.myu2sig.com/EoJCardLibrary.php

If you check out the above link you will see some tables where I'm pulling and displaying DB info. Well, I would like to have some pagination added to it but I can't find a way to do it using the "display method" I want.

This next link which you will find below is a txt file showing all of the code associated with the display of the data.

http://www.myu2sig.com/EoJCardLibrary.txt

Ok, so here's my question... would any of you be kind enough to please add pagination to the code for me but the display aspect of it should look something like this.

<< ? to ? of ? >>

The << & >> should act as the page left and page right buttons where as the ? to ? of ? should be pretty much self explanitory.

So lets say it's set to page at 25 items per page which is what I want, well on page one it should look something like << 1 to 25 of 311 >> and lets say on page 5 it should look something like << 101 to 125 of 311 >> the of ? figure would obviously be the number of records in the table from which the data is pulled and would change accordingly with each new record added.

Oh, and as for the placement of the << ? to ? of ? >> it can go in the td where the ... is which is displayed on the right if you check out the first link.

Recommended Answers

All 2 Replies

If you're looking for someone to write the code for you, that's not going to happen. But I can tell you the basics of how to do this:

-Use a get variable(?min) to keep track of what the first post of the page is. Start it at 0, if $_GET is set(and is a number; is_numeric($_GET), set $min to $_GET.
-Add a second query to select the id of every row, then set $row_count = mysql_num_rows($result)
-Add a limit to your select query("SELECT * FROM Table_name LIMIT $min, 25")
-Make your links at the bottom like this:

// echo the link for the previous page
$previous = $min - 25;
if($previous < 0) {
$previous = 0;
}
$next = $min + 25;
if($next >= $row_count) {
$next = $min;
}
echo "<a href='{$_SERVER['PHP_SELF']}?min=$previous'>&lt;&lt;</a>";

// Display $min, $next, and $row_count for the "1 to 25 out of 311"

// echo the link for the next page
echo "<a href='{$_SERVER['PHP_SELF']}?min=$next'>&gt;&gt;</a>";

Logical flow:
If the user hasn't clicked on anything, $min should be set to 0 and thus select the first post.
Once the user has clicked on a link, ?min will be set to the first post of that page(e.g: 25, 50, etc). Then your links at the bottom will be $min - 25 and $min + 25, basically go back or forward a page.

Notes: You'll want to add extra checking to this to make sure unscrupulous users don't enter unexpected things into the get variable, e.g: SQL queries(hence is_numeric() ), numbers greater than your number of rows or less than 0, etc.

I'd be lying if I said I understood that, as far as getting someone to write the code for me. If they do they do if they don;t they dont but either way it never hurts to try.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.