<?php
  $qry = $_GET["qry"];
  
  require('classes/hippo_sql_query.php');
  require('classes/SimplePager.php');
  //require('classes/strip_quotes.php');
  require('DBVar.php');
  
  if($connection_method == "mysql")
  {
    $my_sql=new hippo_sql_query($connection_method,$host,$dbName1,$dbUser,$dbPass,$dbPort);
    
    $sql_stmt = "SELECT COUNT(*) AS num_rows FROM ".$tbName1." ORDER BY mId DESC";
    
    $res = $my_sql->query_exec($sql_stmt,"4");
    
    $row = $res[0]['num_rows'];
    
    // Define the number of rows per page
    $rowsPerPage=10;
    // Set a default page number
    if(!isset($_GET['page'])){$_GET['page']=1;}
    // Instantiate the pager
    $pager=new SimplePager ($rowsPerPage,$row,$_GET['page']);
    // Now construct the "real" SQL statement
    
    $sql_stmt = "SELECT DISTINCT * FROM ".$tbName1." ORDER BY mId DESC LIMIT ".$pager->getStartRow().", ".$rowsPerPage;
    // $pager->getStartRow() = 0(page=1), 10(page=2), 20(page=3) => if $rowsPerPage=10
    // $pager->getStartRow() = 0(page=1), 20(page=2), 40(page=3) => if $rowsPerPage=20
    
    $res = $my_sql->query_exec($sql_stmt,"4");
  
    for($i=0; $i<count($res); $i++)
    {
      echo $res[$i]['mAccount'].'<br>';
    }
    
    $totalpage=0;
    if($row % $rowsPerPage != 0)
    {
      $totalpage = intval($row/$rowsPerPage)+1;
    }
    elseif($row % $rowsPerPage == 0)
    {
      $totalpage = intval($row/$rowsPerPage);
    }
    
     
    echo "<center>";
    echo "<hr>";
    for($i=0; $i< $totalpage; $i++)
    {
      if($page==($i+1))
      {
        echo ($i+1)."&nbsp;";
      }
      else
      {
       echo "<a href=index.php?page=".($i+1).">".($i+1)."</a>&nbsp;";
      }
    }
    echo "</center>";
  }
?>