Member Avatar for stephen_UK

I have a php script displaying muliple pages of records which has problems with the pagination of the web pages.
When it loads for the first time I get 2 Notice: Undefined index messages - as shown below:

Notice: Undefined index: start in /customers/swaag.org/swaag.org/httpd.www/SWAAG-DATABASE/VIEW_in_STEPS5b.php on line 210
Notice: Undefined index: p_f in /customers/swaag.org/swaag.org/httpd.www/SWAAG-DATABASE/VIEW_in_STEPS5b.php on line 497

See code below:

210  $start=$_GET['start'];								// To take care global variable if OFF
211  if(!($start > 0)) {                         // This variable is set to zero for the first page
212  $start = 0;
213  }

495  ///// Variables set for advance paging///////////
496  $p_limit=20; // This should be more than $limit and set to a value for whick links to be breaked
497  $p_f=$_GET['p_f'];		// To take care global variable if OFF
498  if(!($p_f > 0)) {                         // This variable is set to zero for the first page
499  $p_f = 0;

When I use the script to click from page to page, and even back to the first page, I never see the Notice message again, it only occurs when the page loads for the first time.

I have intialised the $_GET variable with a zero which cures the problem but it interfers with the pagination then.

I have tried to find a way to intialise the $_GET on page load, but then not any more as the script loads further pages - but without success,
but it may be due to my low php skill level.

I have tried to turn off the notifications using the 3 lines below, but again with no effect.

ini_set('error_reporting', E_ALL ^ E_NOTICE);

error_reporting(E_ALL ^ E_NOTICE);

error_reporting(0);

Is there any other way of turning off the Notification when this script runs? or initialising the $_GET's only once when the page loads?

Many thanks in advance

Stephen

Recommended Answers

All 2 Replies

You get this error message because you're trying to retrieve $_GET from the URL when it doesn't exist. Why not check whether the variable exists before deciding what to do with its value.

E.g.

<?php
    if (isset($_GET['start'])) { $start = $_GET['start']; } 
    else { $start = 0; }  
?>

Alternatively, add the start variable in the URL that links to the first page, then you wouldn't have this problem.

<a href="/VIEW_in_STEPS5b.php?start=0"
Member Avatar for stephen_UK

Many thanks nonshatter your a star!

Both solutions worked. Where would we be without folks like your good self who are willing to share their knowledge.

All the best

Stephen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.