Avaliação de Class..
Ola galera Imaster, gostaria que os gurus do forum descem uma olhada na minha class de conexão com bd e paginação tem um exemplo de uso, gostaria que falassem os defeitos e vantagens abordadas e deixo para caso algun iniciante queira usar.
O exemplo possui html para os iniciantes como eu virem que o menu paginação pode ser impresso independente da ordem no html, isso depende do css mas a query com os campos devem ser instanciados antes é claro.
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml%22)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
left:343px;
top:168px;
width:1px;
height:4px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:605px;
top:86px;
width:369px;
height:224px;
z-index:1;
}
#apDiv3 {
position:absolute;
left:605px;
top:25px;
width:368px;
height:54px;
z-index:2;
}
-->
</style>
</head>
<?php
/**
* @author Jefferson Alves Pereira
* @copyright 2008
*/
class model{
#-- tratar perfis como objetos --
protected $host = '127.0.1';
protected $pass = 'qwerty';
protected $user = 'root';
private $tabela;
private $linkdb;
protected $database;
var $consulta;
var $query;
var $campo;
var $coluna ='';
var $anterior;
var $proxima;
var $numeracao;
public function __construct(){
$this->conecta();
}
protected function conecta(){
$this->linkdb = mysql_pconnect($this->host,$this->user,$this->pass) or die ("Falha ao estabelecer dados com o link.".mysql_error());
return $this->linkdb;
}
public function SetQuery($database){
$base = explode('|', $database, -1);
$this->tabela = mysql_select_db($base[0],$this->linkdb) or die ('Falha na tentativa de estabelecer consulta.'.mysql_error());
$this->query = mysql_query( $base[1].' '.$base[2].' '.$base[3],$this->linkdb) or die ('Falha na requisição de consulta.'.mysql_error());
return $this->query;
}
public function SetPrint($valor){
$this->valor = $valor;
return $this->valor;
}
public function SetLoppH($query,$row,$tag = null){
$html = explode('|',$tag,-1);
while ($loop = mysql_fetch_array($this->query)){
echo $html[0].$loop[$this->valor].$html[1];
}
}
public function SetVar($name,$value){
$this->setvar = define($name,$value,TRUE);
return $this->setvar;
}
public function SetPaginacao($query,$campos,$page = 1){
$this->SetQuery($query);
$lpp = $page;#exibição por páginas
$this->pagina = $_GET[pagina];
$total = mysql_num_rows($this->query);
$this->paginas = ceil($total/$lpp);
if(!isset($this->pagina)){$this->pagina = 0;}
$inicio = $this->pagina * $lpp;
$this->SetQuery($query."LIMIT $inicio, $lpp|");
$this->o = $this->SetQuery($query."LIMIT $inicio, $lpp|");
$this->rows = explode('|',$campos,-1);
$this->n = count($this->rows);
while($this->coluna = mysql_fetch_array($this->query)){
for($limite = 0;$limite<$this->n; $limite++){
echo $this->coluna[$this->rows[$limite]].' -- ';
}
}
return $this->coluna[$this->rows[$limite]];
}
public function MenuPaginacao(){
if($this->pagina>0){
$menos = $this->pagina -1;
$url = "$PHP_SELF?pagina=$menos";
echo "<a href=".$url.">Anterior</a>";
}
for($i=0;$i<$this->paginas;$i++){
$url = "$PHP_SELF?pagina=$i";
echo "|<a href=".$url.">$i</a>";
}
if($this->pagina<($this->paginas - 1)){
$mais = $this->pagina + 1;
$url = "$PHP_SELF?pagina=$mais";
echo "|<a href=".$url.">Próxima</a>";
}
}
}
$teste = new model;
/*?>$teste->SetVar(QUERYA,"astro|SELECT * FROM|noticias|LIMIT|");
$teste->SetVar(LIMIT,"$inicio,$lpp");
//$teste->SetLoppH($teste->SetQuery(QUERYA), $teste->SetPrint('texto'),'<br>|<br/>|');<?php */
$teste->SetVar(QUERYB,"chat|SELECT * FROM|messages|ORDER BY `messages`.`id` ASC ");
?>
<body>
<div id="apDiv2"> <?php $teste->SetPaginacao(QUERYB,'user|','1');
$teste->SetPaginacao(QUERYB,'id|');
$teste->SetPaginacao(QUERYB,'time|');
?>
</div>
<div id="apDiv3"> <?php echo $teste->MenuPaginacao(); ?> </div>
</body>
</html>
E se possível caso haja algum nivel em qual eu estou..grato.
Discussão (11)
Carregando comentários...