macfall Posted November 30, 2010 Share Posted November 30, 2010 I'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? Link to comment https://forums.phpfreaks.com/topic/220214-noob-question-using-url-variables-for-next-page-and-previous-page-buttons/ Share on other sites More sharing options...
dawsba Posted December 1, 2010 Share Posted December 1, 2010 you should read up on pagination: but for a dirty way function stripName() //strip the page number from script name { $page = strtolower($_SERVER[php_SELF]); $pref = "page"; // prefix of file name to strip $postf = ".php"; // postfix of file to strip return substr($page,strlen($pref)-1,strlen($page)-(strlen($postf)+strlen($pref))); } function filec($page) //check file exists { if(file_exists($page)){return true;}else{return false;}return false; } $thispage = stripName(); // grab page number $prevpage = $thispage-1; // previous page $nextpage = $thispage+1; // nextpage if(!filec($prevpage)){$prevpage=$thispage;$noprev=1;} // check previous page exists if(!filec($nextpage)){$nextpage=$thispage;$nonext=1;} // check next page exists if(!isset($noprev)){$links = "<a href=\"".$prevpage."\">[ Previous Page ]</a>";} // build the link if previous exists if(!isset($nonext)){$links .= "<a href=\"".$nextpage."\">[ Next Page ]</a>";} // build the link if next exists echo $links; // display links to screen hope this helps Link to comment https://forums.phpfreaks.com/topic/220214-noob-question-using-url-variables-for-next-page-and-previous-page-buttons/#findComment-1141633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.