mallen Posted December 6, 2012 Share Posted December 6, 2012 (edited) I have this list of files that are dynamically listed on a admin page. It lists all the files and I can control the amount per page. Also I can add and delete. So I know all those functions work fine. Here is the problem. I am trying to use a pagination system. It has a drop down box with page numbers. But it will only alow me to select the page once. It lists for example all 4 pages. It doesn't matter if I select page two or four or what order. If I select another page it launches a different page and exits the pagination ect.. breadcrumb=1 Is there anything in my code that could cause this? class literature { protected $numPerPage, $getLits, $totalLit; function __construct() { $this->numPerPage = 9; $this->getLit = $this->getLits(); $this->totalLit = count($this->getLits(true)); } function getLits($count = false) { $curPage = 0; $ltCategory = NULL; if(isset($_REQUEST['breadcrumb'])) $curPage = $this->numPerPage * $_REQUEST['breadcrumb']; if($count) $curPage = -1; return $this->getLitQuery($curPage); } function getLitQuery($curPage = 0) { global $wpdb; $litQuery = "SELECT * FROM literature ORDER BY lit_id ASC"; if($curPage !== -1) $litQuery .= " LIMIT $curPage,". $this->numPerPage; return $wpdb->get_results($wpdb->prepare($litQuery), ARRAY_A); } function getLitInfo($id) { global $wpdb; $query = $vals = $wpdb->get_row($wpdb->prepare("SELECT * FROM literature WHERE `lit_id`='$id' LIMIT 1"), ARRAY_A); return $vals; } function getBreadcrumbs() { $output =""; $totalPages = $this->totalLit / $this->numPerPage; if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id='breadcrumb_page' onchange='getNewBreadcrumbPage(this.value,\""; $output .= "\");'>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= "selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } } } And here are the javascript funtions: function getNewBreadcrumbPage(p, c) { var newpage = p - 1; var location = document.location.href; var existing = gup('breadcrumb'); if(!existing) window.location = location + '&breadcrumb=' + newpage; else { window.location ="?page=edit_literature&productCategory=" + c +"&breadcrumb="+ newpage; } } function gup( name ) { name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return false; else return true; } Edited December 6, 2012 by mallen Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/ Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 What's the result of $totalPages. $totalPages = $this->totalLit / $this->numPerPage; Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397869 Share on other sites More sharing options...
mallen Posted December 6, 2012 Author Share Posted December 6, 2012 2.8888888888889 Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397871 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 Where did you get this piece of code? You got a wrong result of total pages. Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397873 Share on other sites More sharing options...
mallen Posted December 6, 2012 Author Share Posted December 6, 2012 I set the total per page to 9. The drop down shows 3 pages. I echo $totalPages; and get 2.8888888888889 I have 26 files Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397877 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 (edited) Check that statement again and tell us where the code gets stuck. if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id='breadcrumb_page' onchange='getNewBreadcrumbPage(this.value,\""; $output .= "\");'>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= "selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } } EDIT: also check the type of $totalPage: echo gettype($totalPages) Edited December 6, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397880 Share on other sites More sharing options...
mallen Posted December 6, 2012 Author Share Posted December 6, 2012 (edited) I think this line may be the issue output .= "<select id='breadcrumb_page' onchange='getNewBreadcrumbPage(this.value,\""; I can't tell what is getting stuck. For example it give choice of 1,2, 3. You can pick any one the first time. If you pick any other page after this first selection it loads another page. Seems it loses track of what page and breadcrumb its on. The page is page=edit-literature&breadcrumb=2 and it will leave this. Edited December 6, 2012 by mallen Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397881 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 Well, rid all of if statement off from that class and put it a static values, after that just echoing the $output varible! Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397884 Share on other sites More sharing options...
mallen Posted December 6, 2012 Author Share Posted December 6, 2012 (edited) I removed if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) And that didn't work. Got the same results. It needs a dynamic variable for the bread crumb that gets fed to the switch statement. Edited December 6, 2012 by mallen Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397886 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 (edited) Most likely you got a wrong html output, just echo $output and post the results here. Edited December 6, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397887 Share on other sites More sharing options...
mallen Posted December 6, 2012 Author Share Posted December 6, 2012 <div id="adminBreadCrumbs"> <div class='alignRight'> <label>Page:</label><select id='breadcrumb_page' onchange='getNewBreadcrumbPage(this.value)';><option value='1'>1</option> <option value='2'selected>2</option> <option value='3'>3</option> </select>2.8888888888889 </div> Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397898 Share on other sites More sharing options...
jazzman1 Posted December 6, 2012 Share Posted December 6, 2012 (edited) Wrong html! I've tried that one and it works: <?php $totalPages = 2.8888888888889; $output =""; if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id=breadcrumb_page onchange=getNewBreadcrumbPage(this.value)>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= "selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } ?> <script type="text/javascript"> function getNewBreadcrumbPage(data){ alert(data); } </script> EDIT: I added and your javascript function. Don't use $REQUEST ! Edited December 6, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1397934 Share on other sites More sharing options...
mallen Posted December 7, 2012 Author Share Posted December 7, 2012 (edited) Thanks Jazzman1. Not sure what I should use instead of _REQUEST. I tired your code and yes it works by itself. But the URL is not changing. Also my total pages will need to be dynamic. Its displaying data to the javascript pop up window. But in the complete set up it still fails after you select a second page. In any order. My url reads ?page=edit-literature&breadcrumb=1 Then I choose and page My url reads ?page=edit-literature&breadcrumb=2 And the second page in any order whether its page 1 again or page 3 it goes : ?page=different_page_alltogether&breadcrumb=0 And of course the admin page and pagination is all gone because its on another page. Edited December 7, 2012 by mallen Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1398101 Share on other sites More sharing options...
mallen Posted December 12, 2012 Author Share Posted December 12, 2012 I was able to get it fixed. I am sure it had to do with a cookie being set. I learned using _REQUEST includes $_COOKIE. I use some similar pages on other sites I have installed locally and there may be a conflict. I did a search with Dreamweaver and found no other function that could be sending me to another URL. I changed _REQUEST to _POST and to _GET and got a permissions error message. Then I cleared my history and cookies and set it back to _REQUEST. I noticed it was sending me to a URL with and extra '=' and found that in the function inside the javascript. Also I renamed the link on the onchange to make sure it was a unique function and it worked. function getBreadcrumbs() { $output =""; $totalPages = $this->totalLit / $this->numPerPage; if($totalPages > 2) { $output .= "<label>Page:</label>"; $output .= "<select id='breadcrumb_page' onchange='getNewBreadcrumbPageLiterature(this.value)';>"; $output .= "\");'>"; for($i=1; $i<=ceil($totalPages); $i++) { $output .= "<option value='$i'"; if(isset($_REQUEST['breadcrumb']) && $_REQUEST['breadcrumb'] == $i -1) $output.= " selected"; $output .= ">$i</option>\n"; } $output .= "</select>"; echo $output; } } and the Javascript file that is linked: function getNewBreadcrumbPageLiterature(p) { var newpage = p - 1; var location = document.location.href; var existing = gup('breadcrumb'); if(!existing) window.location = location + '&breadcrumb=' + newpage; else { window.location ="?page=edit-literature" +"&breadcrumb="+ newpage; } } Quote Link to comment https://forums.phpfreaks.com/topic/271679-pagination-cannot-select-a-second-page/#findComment-1398915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.