karthikanov24 Posted May 22, 2009 Share Posted May 22, 2009 HI IN THE getpaginglink() FUNCTION AT ADMIN MODULE OF SHOPPING CART,WHATS USE OF $numLinks = 10;,IF WE HAVE 4 PAGES TO DISPLAY AND EACH PAGE HAVE 10 RECORDS(ROWS)...AS ONLY 4 LINKS ARE NECESSARY...THEN WHY 10 LINKS?? WHETHER $pagenumber IS WHAT WE CLICKED ON THE LINK PAGE NUMBER SAY 2 OR 3 THAT IS DISPLAYED AT THE BOTTOM OF ADMIN-CATEGORY- VIEW- PAGE LIKE 1|2|3|4| ?? ------------ WHATS THE USE OF $start,$end,$numlink IN THE FOLLOWING PART? $start = $pageNumber - ($pageNumber % $numLinks) + 1; $end = $start + $numLinks - 1; $end = min($totalPages, $end); Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/ Share on other sites More sharing options...
Philip Posted May 22, 2009 Share Posted May 22, 2009 HI - I THINK YOUR CAPS IS A BIT STICKY, BUT APPARENTLY SO IS MINE We have no idea what that function looks like without the code for the function Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840053 Share on other sites More sharing options...
karthikanov24 Posted May 22, 2009 Author Share Posted May 22, 2009 THE CODE IS: function getPagingLink($sql, $itemPerPage = 10, $strGet = '') { $result = dbQuery($sql); $pagingLink = ''; $totalResults = dbNumRows($result); $totalPages = ceil($totalResults / $itemPerPage); // how many link pages to show $numLinks = 10; // create the paging links only if we have more than one page of results if ($totalPages > 1) { $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ; if (isset($_GET['page']) && (int)$_GET['page'] > 0) { $pageNumber = (int)$_GET['page']; } else { $pageNumber = 1; } // print 'previous' link only if we're not // on page one if ($pageNumber > 1) { $page = $pageNumber - 1; if ($page > 1) { $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> "; } else { $prev = " <a href=\"$self?$strGet\">[Prev]</a> "; } $first = " <a href=\"$self?$strGet\">[First]</a> "; } else { $prev = ''; // we're on page one, don't show 'previous' link $first = ''; // nor 'first page' link } // print 'next' link only if we're not // on the last page if ($pageNumber < $totalPages) { $page = $pageNumber + 1; $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> "; $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> "; } else { $next = ''; // we're on the last page, don't show 'next' link $last = ''; // nor 'last page' link } $start = $pageNumber - ($pageNumber % $numLinks) + 1; $end = $start + $numLinks - 1; $end = min($totalPages, $end); $pagingLink = array(); for($page = $start; $page <= $end; $page++) { if ($page == $pageNumber) { $pagingLink[] = " $page "; // no need to create a link to current page } else { if ($page == 1) { $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> "; } else { $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> "; } } } $pagingLink = implode(' | ', $pagingLink); // return the page navigation link $pagingLink = $first . $prev . $pagingLink . $next . $last; } return $pagingLink; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840104 Share on other sites More sharing options...
karthikanov24 Posted May 23, 2009 Author Share Posted May 23, 2009 i request u to reply my question... Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840532 Share on other sites More sharing options...
jkewlo Posted May 23, 2009 Share Posted May 23, 2009 I request that your TURN CAPS OFF NEXT TIME AND BE MORE CLEAR ON YOU QUESTIONS AND USE THE [ code ] [ /code ] TAGS TO PUT CODE IN. it makes it easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840535 Share on other sites More sharing options...
Ken2k7 Posted May 23, 2009 Share Posted May 23, 2009 I answered in the first topic you created. They are used for pagination. Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840536 Share on other sites More sharing options...
karthikanov24 Posted May 23, 2009 Author Share Posted May 23, 2009 oh! well i will correct it next time.. i am not clear in the pagination concept of php. i cant understand following lines $start = $pageNumber - ($pageNumber % $numLinks) + 1; $end = $start + $numLinks - 1; $end = min($totalPages, $end); of the code: can u explain the pagination concept or send me best tutorials for that so that i can learn pagination concept of the following code of shopping cart The function is: function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET['page']) && (int)$_GET['page'] > 0) { $page = (int)$_GET['page']; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between one result page to another. Supply a value for $strGet if the page url already contain some GET values for example if the original page url is like this : http://www.phpwebcommerce.com/plaincart/index.php?c=12 use "c=12" as the value for $strGet. But if the url is like this : http://www.phpwebcommerce.com/plaincart/index.php then there's no need to set a value for $strGet */ function getPagingLink($sql, $itemPerPage = 10, $strGet = '') { $result = dbQuery($sql); $pagingLink = ''; $totalResults = dbNumRows($result); $totalPages = ceil($totalResults / $itemPerPage); // how many link pages to show $numLinks = 10; // create the paging links only if we have more than one page of results if ($totalPages > 1) { $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ; if (isset($_GET['page']) && (int)$_GET['page'] > 0) { $pageNumber = (int)$_GET['page']; } else { $pageNumber = 1; } // print 'previous' link only if we're not // on page one if ($pageNumber > 1) { $page = $pageNumber - 1; if ($page > 1) { $prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> "; } else { $prev = " <a href=\"$self?$strGet\">[Prev]</a> "; } $first = " <a href=\"$self?$strGet\">[First]</a> "; } else { $prev = ''; // we're on page one, don't show 'previous' link $first = ''; // nor 'first page' link } // print 'next' link only if we're not // on the last page if ($pageNumber < $totalPages) { $page = $pageNumber + 1; $next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> "; $last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> "; } else { $next = ''; // we're on the last page, don't show 'next' link $last = ''; // nor 'last page' link } $start = $pageNumber - ($pageNumber % $numLinks) + 1; $end = $start + $numLinks - 1; $end = min($totalPages, $end); $pagingLink = array(); for($page = $start; $page <= $end; $page++) { if ($page == $pageNumber) { $pagingLink[] = " $page "; // no need to create a link to current page } else { if ($page == 1) { $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> "; } else { $pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> "; } } } $pagingLink = implode(' | ', $pagingLink); // return the page navigation link $pagingLink = $first . $prev . $pagingLink . $next . $last; } return $pagingLink; } ?> i hope u got my question! Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840651 Share on other sites More sharing options...
MadTechie Posted May 23, 2009 Share Posted May 23, 2009 it works out the start and end page. Oh and being rude will get less helps heres some php pagination also this should be in the "third party" section as you didn't write it yourself Quote Link to comment https://forums.phpfreaks.com/topic/159280-what-is-the-use-of/#findComment-840654 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.