Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Pagination not going to next page.

    Okay I got it to show no pages when there is no records in the database.

    And I also got it to show when there are records in the database to show pages.

    But now the pages don't work. When I click to go to page 2 it shows the first 4 records from page 1.

    PHP Code:
    <?php
    include("inc/config.php");
    if (isset(
    $_POST['del'])) 
    {
      for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM accounts WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting accounts! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
      echo 
    "<table class=\"gridtable\">
    <thead>
        <tr>
            <th align=\"center\" scope=\"col\">Username</th>
            <th align=\"center\" scope=\"col\">Password</th>
            <th align=\"center\" scope=\"col\">Highscores</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
            <th align=\"center\" scope=\"col\">Status</th>
           <th align=\"center\" scope=\"col\">Delete?</th>
        </tr>
    </thead>
    <tbody>"
    ;
    echo 
    "<form name = 'myform' action='' method='post'>";


    $data mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
    $rows mysql_num_rows($data);
    $page_rows 4;
    $max_pages ceil($rows/$page_rows);

    $page = (int) $_GET['pagenum'];
    $pagenum = ($page && $page && $page <= $last) ? $page 1;
    $last ceil($rows/$page_rows);

    $max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
    $data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error());  
    while(
    $info mysql_fetch_array$data_p ))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    "<td class=\"valid\" >" $info['username'] . "</td>";
      echo 
    "<td class=\"valid\" >" $info['password'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1="$info['username'] ."'>Check Highscores</a></td>"
      echo 
    "<td>" $info['addeddate'] . "</td>";
      echo 
    "<td>" $info['ip'] . "</td>";
      echo 
    "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
       echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo 
    "<hr>";
    if (
    $pagenum == 1)
    {
    }
    else
    {
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
    echo 
    " | ";
    echo 
    " ";
    $previous $pagenum-1;
    $current $pagenum;
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
    echo 
    " | ";
    }
    echo 
    "$pagenum";
    if (
    $pagenum == $last)
    {
    }
    else {
    $next $pagenum+1;
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
    echo 
    " ";
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
    }
    ?>
    Anyone know the problem or see the problem?

    I am also getting no errors

    I am getting this notice error on the index.php page:

    Code:
    Notice: Undefined index: pagenum in /home/runehost/public_html/index.php on line 332


    And this notice error when I add index?pagenum=2 (It doesnt matter what number it gives the same notice error:
    Code:
    Notice: Undefined variable: last in /home/runehost/public_html/index.php on line 333
    Does anyone see the problem?

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You have this:
    PHP Code:
    $pagenum = ($page && $page && $page <= $last) ? $page 1
    $last is not defined before you're using it (that's the undefined notice), so it's getting the value zero. page=2 is not less than or equal to zero, so pagenum=1 and your first page results are returned again and again.
    Are you a Help Vampire?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Okay I have fixed that. I am now getting this error:


    Code:
    Notice: Undefined index: pagenum in /home/runehost/public_html/accounts.php on line 330
    with this code:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    include(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {
      for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM accounts WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting accounts! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
      echo 
    "<table class=\"gridtable\">
    <thead>
        <tr>
            <th align=\"center\" scope=\"col\">Username</th>
            <th align=\"center\" scope=\"col\">Password</th>
            <th align=\"center\" scope=\"col\">Highscores</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
            <th align=\"center\" scope=\"col\">Status</th>
           <th align=\"center\" scope=\"col\">Delete?</th>
        </tr>
    </thead>
    <tbody>"
    ;
    echo 
    "<form name = 'myform' action='' method='post'>";


    $data mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
    $rows mysql_num_rows($data);
    $page_rows 4;
    $page = (int) $_GET['pagenum'];
    $max_pages ceil($rows/$page_rows);
    $last ceil($rows/$page_rows);
    $pagenum = ($page && $page && $page <= $last) ? $page 1;

    $max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
    $data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error());  
    while(
    $info mysql_fetch_array$data_p ))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    "<td class=\"valid\" >" $info['username'] . "</td>";
      echo 
    "<td class=\"valid\" >" $info['password'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1="$info['username'] ."'>Check Highscores</a></td>"
      echo 
    "<td>" $info['addeddate'] . "</td>";
      echo 
    "<td>" $info['ip'] . "</td>";
      echo 
    "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
       echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo 
    "<hr>";
    if (
    $pagenum == 1)
    {
    }
    else
    {
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
    echo 
    " | ";
    echo 
    " ";
    $previous $pagenum-1;
    $current $pagenum;
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
    echo 
    " | ";
    }
    echo 
    "$pagenum";
    if (
    $pagenum == $last)
    {
    }
    else {
    $next $pagenum+1;
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
    echo 
    " ";
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
    }
    ?>
    what do I do to fix that? also, it shows this
    when there are no records in the database:

    Picture:


    See the:

    1 | 2 | Last

    Its supposed to hide when there are no records.

    Can someone help me out?
    Last edited by bucket; 11-03-2009 at 11:55 PM.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    It's not a cryptic message. Look at the line in the notice. I suspect it's here:
    PHP Code:
    $page = (int) $_GET['pagenum']; 
    That means pagenum isn't defined, which is to say that it's not present in the GET string. If you don't want to see the notice, check for isset first.
    Are you a Help Vampire?

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    How would I do that? Can you please post what I should change or add to the script.

    Thank You.

  • #6
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I fixed that error:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    include(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {
      for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM accounts WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting accounts! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
      echo 
    "<table class=\"gridtable\">
    <thead>
        <tr>
            <th align=\"center\" scope=\"col\">Username</th>
            <th align=\"center\" scope=\"col\">Password</th>
            <th align=\"center\" scope=\"col\">Highscores</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
            <th align=\"center\" scope=\"col\">Status</th>
           <th align=\"center\" scope=\"col\">Delete?</th>
        </tr>
    </thead>
    <tbody>"
    ;
    echo 
    "<form name = 'myform' action='' method='post'>";
    $data mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
    $rows mysql_num_rows($data);
    $page_rows 4;
    if(!isset(
    $_GET['pagenum']))
    {
    $page 1;
    }
    else
    {
    $page = (int) $_GET['pagenum'];
    }




    $max_pages ceil($rows/$page_rows);
    $last ceil($rows/$page_rows);
    $pagenum = ($page && $page && $page <= $last) ? $page 1;

    $max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
    $data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error());  
    while(
    $info mysql_fetch_array$data_p ))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    "<td class=\"valid\" >" $info['username'] . "</td>";
      echo 
    "<td class=\"valid\" >" $info['password'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1="$info['username'] ."'>Check Highscores</a></td>"
      echo 
    "<td>" $info['addeddate'] . "</td>";
      echo 
    "<td>" $info['ip'] . "</td>";
      echo 
    "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
       echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo 
    "<hr>";
    if (
    $pagenum == 1)
    {
    }
    else
    {
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
    echo 
    " | ";
    echo 
    " ";
    $previous $pagenum-1;
    $current $pagenum;
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
    echo 
    " | ";
    }
    echo 
    "$pagenum";
    if (
    $pagenum == $last)
    {
    }
    else {
    $next $pagenum+1;
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
    echo 
    " ";
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
    }
    ?>

    what do I do to fix that? also, it shows this
    when there are no records in the database:

    Picture:


    See the:

    1 | 2 | Last

    Its supposed to hide when there are no records.

    Can someone help me out?
    Last edited by bucket; 11-04-2009 at 12:18 AM.

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Fixed that too:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    include(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {
      for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM accounts WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting accounts! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
      echo 
    "<table class=\"gridtable\">
    <thead>
        <tr>
            <th align=\"center\" scope=\"col\">Username</th>
            <th align=\"center\" scope=\"col\">Password</th>
            <th align=\"center\" scope=\"col\">Highscores</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
            <th align=\"center\" scope=\"col\">Status</th>
           <th align=\"center\" scope=\"col\">Delete?</th>
        </tr>
    </thead>
    <tbody>"
    ;
    echo 
    "<form name = 'myform' action='' method='post'>";
    $data mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
    $rows mysql_num_rows($data);
    $page_rows 4;
    if(!isset(
    $_GET['pagenum']))
    {
    $page 1;
    }
    else
    {
    $page = (int) $_GET['pagenum'];
    }




    $max_pages ceil($rows/$page_rows);
    $last ceil($rows/$page_rows);
    $pagenum = ($page && $page && $page <= $last) ? $page 1;

    $max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
    $data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error());  
    while(
    $info mysql_fetch_array$data_p ))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    "<td class=\"valid\" >" $info['username'] . "</td>";
      echo 
    "<td class=\"valid\" >" $info['password'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1="$info['username'] ."'>Check Highscores</a></td>"
      echo 
    "<td>" $info['addeddate'] . "</td>";
      echo 
    "<td>" $info['ip'] . "</td>";
      echo 
    "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
       echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo 
    "<hr>";
    if (
    $pagenum == 1)
    {
    }
    else
    {
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
    echo 
    " | ";
    echo 
    " ";
    $previous $pagenum-1;
    $current $pagenum;
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
    echo 
    " | ";
    }
    echo 
    "$pagenum";
    if (
    $pagenum == $last || $last == 0)
    {
    }
    else {
    $next $pagenum+1;
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
    echo 
    " ";
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
    }
    ?>
    Now all I need is instead of showing a blank table for it to just say

    'No Logged Accounts'

  • #8
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I got it:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');

    include(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {
      for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM accounts WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting accounts! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM accounts");
    if(
    mysql_num_rows($result) > 0)
    {

      echo 
    "<table class=\"gridtable\">
    <thead>
        <tr>
            <th align=\"center\" scope=\"col\">Username</th>
            <th align=\"center\" scope=\"col\">Password</th>
            <th align=\"center\" scope=\"col\">Highscores</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
            <th align=\"center\" scope=\"col\">Status</th>
           <th align=\"center\" scope=\"col\">Delete?</th>
        </tr>
    </thead>
    <tbody>"
    ;
    echo 
    "<form name = 'myform' action='' method='post'>";
    $data mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
    $rows mysql_num_rows($data);
    $page_rows 4;
    if(!isset(
    $_GET['pagenum']))
    {
    $page 1;
    }
    else
    {
    $page = (int) $_GET['pagenum'];
    }


    $max_pages ceil($rows/$page_rows);
    $last ceil($rows/$page_rows);
    $pagenum = ($page && $page && $page <= $last) ? $page 1;

    $max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
    $data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error());  
    while(
    $info mysql_fetch_array$data_p ))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    "<td class=\"valid\" >" $info['username'] . "</td>";
      echo 
    "<td class=\"valid\" >" $info['password'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1="$info['username'] ."'>Check Highscores</a></td>"
      echo 
    "<td>" $info['addeddate'] . "</td>";
      echo 
    "<td>" $info['ip'] . "</td>";
      echo 
    "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
      echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo 
    "<hr>";



    if (
    $pagenum == 1)
    {
    }
    else
    {
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
    echo 
    " | ";
    echo 
    " ";
    $previous $pagenum-1;
    $current $pagenum;
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
    echo 
    " | ";
    }
    echo 
    "$pagenum";
      if (
    $pagenum == $last || $last == 0)
    {
    }
    else 
    {
    $next $pagenum+1;
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
    echo 
    " ";
    echo 
    " | ";
    echo 
    " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
    }
    }
    else
    {
    // No rows were found ...
    echo '<center>No logged accounts.</center><hr>'
    }
    ?>
    I had to add this in the beggining
    PHP Code:
    $result mysql_query("SELECT * FROM accounts");
    if(
    mysql_num_rows($result) > 0)


    and this at the end:
    PHP Code:
    }
    else
    {
    // No rows were found ...
    echo '<center>No logged accounts.</center><hr>'



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •