How $_GET['pageno']) works in php paginati

2019-09-04 19:11发布

问题:

I am new to php. I have a website were i want to show data's in different pages. I have come across lots of pagination script ( eg http://www.tonymarston.net/php-mysql/pagination.html). In this website he is given isset($_GET['pageno']) in his script. I know that its for total no of pages, but how its done in the first place..its confusing and can any one please explain.

Thanks in advance

回答1:

You should look up HTTP requests and what they mean.

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

The most common one is GET. Which is any typical URL request. If you click on the above link, you are submitting a GET request. So if you add a parameter to that URL.. lets say..

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol?pageno=2

...then the page that is executed by your GET will have the pageno parameter in it's GET scope with the value of 2. The way that is retrieve in PHP is

var $page = $_GET['pageno'];

$_GET is a global reserved variable in PH. As is $_POST - another common HTTP Request.

isset() simply asks the question whether a variable has been assigned .. or "is set".

http://php.net/manual/en/function.isset.php

http://php.net/manual/en/reserved.variables.get.php

http://php.net/manual/en/reserved.variables.post.php



回答2:

He doessng gives isset($_GET['pageno']), but $_GET['pageno']. The first time the $_GET['pageno'] is not set, so $pageno = 1 :

if (isset($_GET['pageno'])) { // if there is anything set in $_GET['pageno']
   $pageno = $_GET['pageno']; // $pageno whoult be the value in $_GET['pageno']
} else { 
   $pageno = 1; // nothing is set in $_GET['pageno'], so $pageno is 1
} // if