Jump to content

Pagination Help


gouc89

Recommended Posts

I'm trying to get all of my records to display in my PrimaryContent DIV, but only the first one does. When you click on any other pages, they display on a completely separate page. I was told to Google "passing multiple variables in a query string" but there was so much coding that I was completely lost. I was also told,

 

"Find the place in the code where the page=xxx is set in the URL (First << 1 2 3 etc.). Add your Menukey to the Query String. Every time the page reloads, check for the MenuKey and let the Function check for the Page Number."

 

The part I don't really understand is how I add my menukey to the query string.

 

Any help would be appreciated. If you need to see any specific code let me know. My page is here so you can see for yourself:

 

http://itd1.cincinnatistate.edu/php_vondrelld/index.php?menukey=8

 

Scroll to the bottom and click another page and you'll see what I mean.

 

Thanks so much!

Link to comment
Share on other sites

The "menukey" you see in your query string is...the menukey from the query string. The query string is the last bit of the URL.

 

If you need to pass multiple variables in a query string, you separate them with an ampersand:

yourfile.php?menukey=8&page=3

Link to comment
Share on other sites

I see that, but when I go to index.php?menukey=8&page=3, still the first page loads. Where do I change it in the code?

 

For instance, right now I've got this code for clicking "Next":

 

return '<a href="'.$this->php_self.'?page='.($this->page+1).'">'.$tag.'</a>';

 

Do I change something in there? Or somewhere in the paginate function?

Link to comment
Share on other sites

$this->php_self is incorrect. Depending on your setup it might be easiest just to plug in a href='http://yoursite.com/index.php?menukey=8&page=2'

 

$this->php_self might be unsafe, depending on what that class is doing with it. There are known exploits with using $_SERVER['PHP_SELF'] directly, but if the class is handing that, then it might be safe.

 

I see that, but when I go to index.php?menukey=8&page=3, still the first page loads. Where do I change it in the code?

 

Your script needs to pick up the page value that is requested using $_GET['page'] and use that to select the data for the page. Without seeing some code, we can't really tell where you are going wrong.

Link to comment
Share on other sites

Here's the code I have where $_GET['page'] is:

 

function PS_Pagination($connection, $sql, $rows_per_page = 10, $links_per_page = 5) {

$this->conn = $connection;

$this->sql = $sql;

$this->rows_per_page = $rows_per_page;

$this->links_per_page = $links_per_page;

$this->php_self = htmlspecialchars($_SERVER['PHP_SELF']);

if(isset($_GET['page'])) {

$this->page = intval($_GET['page']);

}

Link to comment
Share on other sites

$this->php_self might be unsafe, depending on what that class is doing with it. There are known exploits with using $_SERVER['PHP_SELF'] directly, but if the class is handing that, then it might be safe.

 

What I meant by it's incorrect is it's coming up with the wrong url. When you click on the page # it sends you to a completely different url.

Link to comment
Share on other sites

To build your pagination links, while keeping any existing get parameters or letting a different section of your code set their own get parameters, see the use of http_build_query in the following pagination example - http://forums.phpfreaks.com/topic/268497-pagination/page__hl__+http_build_query#entry1378864

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.