I am using the JPagination to paginig results from a MySQL database The code works, but I am getting the following error: Notice: Undefined index: page in C:\xampp\htdocs\paginate\page.php on line 11
Files
index.php
[...]
<head>
<link rel="stylesheet" type="text/css" href="style.css" media="screen"/>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script src="jquery.paginate.js" type="text/javascript"></script>
</head>
<body>
<?php require('db.php'); ?>
<?php require('page.php'); ?>
<div class="demo">
<div id="pagetxt">
<?php
$consulta = "select * from rec order by id desc limit 0,10";
$result = mysqli_query($con, $consulta);
while($row = mysqli_fetch_array($result)){
echo "<p>" .$row["id"]."<a>".$row["titulo"]."</a></p>";
}
?>
</div>
<div id="demo1"></div>
</div>
<script type='text/javascript'>
$(document).ready(function(){
$("#demo1").paginate({
count: "<?php echo $page;?>",
start:1,
display:10,
border:true,
border_color:'#BEF8B8',
text_color:'#79B5E3',
background_color:'#E3F2E1',
border_hover_color:'#68BA64',
text_hover_color:'#2573AF',
background_hover_color:'#CAE6C6',
images:false,
mouse:'press',
onChange:function(page){
$("#pagetxt").load("page.php?page="+page);
}
})
})
</script>
</body>
page.php
<?php
include("db.php");
$consultab = "select count(*) as c from rec";
$resultb = mysqli_query($con, $consultab);
$row = mysqli_fetch_array($resultb);
$total = $row['c'];
$pagesize = 10;
$page = ceil($total/$pagesize);
$start = ($_GET['page'] - 1)*$pagesize;
if(isset($_GET['page'])){
$consulta = "select * from rec order by id asc limit $start,$pagesize";
$result = mysqli_query($con, $consulta);
while($row = mysqli_fetch_array($result)){
echo "<p>".$row["id"]."<a>
".$row["titulo"]."</a></p>";
}
}
?>
If i manually write index.php?page=1 in the address bar the error disappear but i get 20 items in the pagination, the first 10 items and the last 10 items.
This question seems a duplicate but it's not, my problem not only consists in an undefined index error . I am new to php and mysql, and what I need is to find out how I can fix this code to display results correctly. Could someone help me?