PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Mehran Karbassi   Persian Db Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Persian Db Class
Execute MySQL queries and paginate results
Author: By
Last change:
Date: 11 years ago
Size: 1,194 bytes
 

Contents

Class file image Download
<?php

$LEN
=10;
$pg=1;
if (isset(
$_GET['page']))
   
$pg = is_numeric($_GET['page']) ? ($_GET['page']) : 1;

function
MakePagination($arr, $pg=1)
{
    if (!
is_array($arr))
        return
'';
   
$c = count($arr)-2;
   
$first = $last = $prev = $next = 1;
   
$prev = $arr[1];
   
$next = $arr[$c];
   
$last = $arr[$c+1];

   
$html = '';
   
$html .= '<a href="del_news.php?page='. $first .'"><<</a> ';
   
$html .= '<a href="del_news.php?page='. $prev .'"><</a> ';
   
    for (
$i=2; $i<$c; $i++):
       
$page = $arr[$i];
        if (
$pg == $page)
           
$html .= '<strong>'. $page .'</strong> ';
        else
           
$html .= '<a href="del_news.php?page='. $page .'">'. $page .'</a> ';
    endfor;
   
   
$html .= '<a href="del_news.php?page='. $next .'">></a> ';
   
$html .= '<a href="del_news.php?page='. $last .'">>></a> ';

    return
$html;
}

require(
"../../class/database/db.class.php");
       
$db=new DB();
        if(
$db->connect()){
$db->connect_db();
           
$from = ($pg-1) * $LEN;
       
$row=$db->select("news","id,name,stat,date","","id desc", "$from,$LEN");
       
       
       
        }
   
   
$paginate = $db->Paginate('news', "", $pg,$LEN);
    if (
$paginate !== false)
    {
       
        echo
MakePagination($paginate, $pg);
        echo
'</p>';
    }

?>