-4

i have search page where i limit results and split pages....... hi i am using "$page = $_GET['page'];" command but if there is no ?page=1 then it is displaying ""Error Undefined index: page"" if i put ?page=1 then there is no error. my problem is this that at the very first time when i run my page print_marks.php then i can not put ?page=1 but when i press next button within the page ?page=2 automatically appeares in the url.

here is my code

$query = "SELECT COUNT(mdl_assignment_submissions.userid) As num FROM mdl_assignment_submissions Where mdl_assignment_submissions.assignment = 1";
    $total_pages = mysql_fetch_array(mysql_query($query));
    $total_pages = $total_pages['num'];


    $targetpage = "Print_Marks.php";    
    $limit = 25;    
    $page = "1";
    $page = $_GET['page'];

    if($page) 
        $start = ($page - 1) * $limit;          
    else
        $start = 0; 
Shivesh Jaiswal
  • 107
  • 2
  • 3
  • 13

2 Answers2

2

Try to use instead

$page = $_GET['page'];

this

$page = isset($_GET['page']) ? $_GET['page'] : 1;
Alexander
  • 807
  • 5
  • 10
1

You could use $page = (isset($_GET['page']) ? $_GET['page'] : 1;

You're getting the error because sometimes page is not set.

Mihai
  • 26,325
  • 7
  • 66
  • 81
Simon R
  • 3,732
  • 4
  • 31
  • 39