Reputation: 823
I found a tutorial according pagination. http://papermashup.com/easy-php-pagination/
I tried the code and it work. but every time the first index is reload(first result in pagination).
I got this message.
Notice: Undefined index: page in C:\xampp\htdocs\sim\registrar\index.php on line 207
how can I remove this message?
here's the code..
$targetpage = "index.php";
$limit = 3;
$query = "SELECT COUNT(*) as num FROM advisoryclass";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string($_GET['page']);//this part
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
thanks
Upvotes: 0
Views: 50
Reputation: 3027
You need to handle if $page does not exist.
$page = mysql_escape_string(isset($_GET['page']) ? $_GET['page'] : 0);
Upvotes: 0
Reputation: 21759
add a check in order to see if the parameter is in the get array:
$page = mysql_escape_string(isset($_GET['page']) ? $_GET['page'] : 0);
this is a ternary comparison in order to make it shorter than an if statement.
Upvotes: 1
Reputation: 19308
You're assuming page
is set when that's not always going to be the case; hence the error.
Change this:
$page = mysql_escape_string($_GET['page']);//this part
To:
$page = ( isset( $_GET['page'] ) ) ? mysql_escape_string( $_GET['page'] ) : 1;
In the code above we're checking the page $_GET
variable has been set and using 1 as a fallback.
You may want to look at the functions you're using with the database too.
Upvotes: 1