开发者

Pagination: How can I handle an error if the parameter is not passed in get request in php?

$pagenum=$_GET['pagenum'];

I have written a code for pagination in a single file. When I open the first time that page, it gives me an error. I think it is because parameter pagen开发者_JAVA百科um is not passed in GET request. How can i handle this?

Otherwise the code is running perfectly. But the issue is to handle that error when opening the page for the first time...


you could write it something like this, to where if there is no page number specified it defaults to 1

$pagenum=isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1;


PHP pages shouldn't break by not receiving a parameter. I'd check elsewhere. What error are you getting?


If the variable is not set, simply display the first x number of records.


if(!isset($_GET['pagenum']))
{
  $pagenum = '1';
}
else
{
  $pagenum = intval($_GET['pagenum']);
}


try

$pagenum = 1;

if(isset($_GET['pagenum'])) {
  $pagenum = $_GET['pagenum'];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜