1
I’m trying to develop a global class for pagination
Follow the code:
class Pager {
private $Sql;
private $Limit;
private $ArgType;
private $Page;
private $Arguments;
private $ArgNumber;
private $Connect;
private $result=array();
public function setSql($Sql){
$this->Sql=$Sql;
return false;
}
public function setLimit($Limit){
$this->Limit=$Limit;
return false;
}
public function setArguments(){
$this->Arguments=func_get_args();
$this->ArgNumber=func_num_args();
return false;
}
public function setArgType($ArgType){
$this->ArgType=$ArgType;
return false;
}
public function setConnect($Connect){
$this->Connect=$Connect;
return false;
}
public function setPage($Page){
$this->Page= isset($Page)?$Page:1;
return false;
}
private function countRegister(){
$Pager = $this->Connect->prepare($this->Sql);
switch ($this->ArgNumber){
case 1:
$Pager->bind_param($this->ArgType,$this->Arguments[0]);
break;
case 2:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1]);
break;
case 3:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2]);
break;
case 4:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2],$this->Arguments[3]);
break;
case 5:
$Pager->bind_param($this->ArgType,$this->Arguments[0],$this->Arguments[1],$this->Arguments[2],$this->Arguments[3],$this->Arguments[4]);
break;
}
$Pager->execute();
$Pager->store_result();
return $Pager->num_rows;
$Pager->close();
}
private function countPages($NumReg){
return ceil($NumReg/$this->Limit);
}
private function prevPage(){
if($this->Page>1)
return $this->Page-1;
else
return false;
}
private function nextPage(){
if($this->Page<$this->result['Pages'])
return $this->Page+1;
else
return false;
}
private function getStart(){
return ($this->Page-1)*$this->Limit;
}
public function execPager(){
$this->result['Pages'] = $this->countPages($this->countRegister());
$this->result['PrevPage'] = $this->prevPage();
$this->result['NextPage'] = $this->nextPage();
$this->result['Start'] = $this->getStart();
$this->result['Limit'] = $this->Limit;
return false;
}
public function getPager(){
return $this->result;
}
}
But in the private function execPage()
I don’t see a way to do the bind_param
with the array
who picked up the function setArguments
the only way was using a case with predefined possibilities
Any suggestions on how to pass these parameters to the function and be able to perform in this way?
I am using mysqli and the class is in early stage in function setArgument
I’ll pass N arguments and put the argument type by the function setArgType
and the same will be a string
then I’ll put it inside the bind_param
thus
$Pager->bind_param($this->setArgType, [Todos os N argumentos da setArguments]);
Cade the
bind_param()
get’s(sql, limit, connect) should not return something instead of assigning?– rray
actually the name is contrary to the use, I’m doing it a little bit hasty today, but the intention is to assign values, as the goal is to leave working first to improve after I didn’t stop to think about the correct name of the variables
– RodrigoBorth
I’ll upgrade to set
– RodrigoBorth
now you’ve become more understanding
– RodrigoBorth