Все ленты — последние статьи

Постраничный вывод на PHP из БД Firebird

Частично код взят из Интернет, но лично переботан и доведен до рабочего состояния.

 

 

<meta charset="utf-8">

<?php

$dbname = '1.1.1.1:akosta';
$dbuser = 'sysdba';
$dbpassword = 'passw';
$connection = ibase_connect($dbname, $dbuser, $dbpassword);
$filename = BASENAME(__FILE__);

 

$strsql = "SELECT FIRST 20 * FROM TORG order by ID desc";
$result = ibase_query($connection, $strsql);

function ibase_num_rows($query) {
$i = 0;
while (ibase_fetch_row($query)) {
    $i++;
  }
return $i;
}
$nrow = ibase_num_rows($result);//sum of row
$strSQL = "SELECT FIRST 20 * FROM TORG order by ID desc";
$result = ibase_query($connection, $strSQL);


if(!isset($_GET['page'])){
  $page = 1;
}
else{
  $page = addslashes(strip_tags(trim($_GET['page'])));
  $page = ereg_replace("[^0-9]", "", $page);
  if($page < 1) $page = 1;
}


$i = 0;
$recperpage = 6;
$norecord = ($page — 1) * $recperpage;
if ($norecord){
  $j=0;
  while($j < $norecord and $row = ibase_fetch_object($result)){

  $j++;
  }
}
echo "<table border=1>";
while ($row = ibase_fetch_object($result) and $i < $recperpage){


 echo "<tr>";
       $tbl_p1 = $row->ID; $tbl_p1 = iconv("WINDOWS-1251", "UTF-8", $tbl_p1); echo "<td>$tbl_p1</td>"; //1 столбец
       echo "<td>2</td>";
       $tbl_p6 = $row->TR5; $tbl_p6 = iconv("WINDOWS-1251", "UTF-8", $tbl_p6); echo "<td>$tbl_p6</td>"; //7 столбец
       
    echo "</tr>";

$i++;
}

$incr = $page + 1;
if ($page > 1) $decr = $page — 1;

$numOfPage = ceil($nrow/$recperpage);

echo    "<tr>";
echo "<td colspan=\"3\" align=\"center\">";

if ($page <= 1)
                    echo "<span>Prev</span>";
                  else
                      echo "<a href="/.$filename."?page=".$decr.">Prev</a>";
             
              echo "  &nbsp;&nbsp;";
              
                if ($page == $numOfPage)
                    echo "<span>Next</span>";
                  else
                      echo "<a href="/.$filename."?page=".$incr.">Next</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
?>