Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP error message

Newbie
 
Join Date: Oct 2009
Posts: 31
#1: Oct 16 '09
Hi All,

Lost my marbles with this one.

The error im recieving is


Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /Applications/MAMP/htdocs/oceanflow/pages/classes.php on line 117

if i add a close brace at the end i get "unexpected $end"

Here is the code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. class paginator extends db
  4. {
  5.     public $data;
  6.     public $query;
  7.     public $perpage;
  8.     public $shortest = 5;
  9.     public $fluctuation = 3;
  10.     public $pg;
  11.     public $start;
  12.  
  13.     public function __construct($params)
  14.     {
  15.         if(!empty($params['perpage']))
  16.         $this->perpage = $params['perpage'];
  17.         else $this->perpage = 10;
  18.  
  19.         if(!empty($params['query']))
  20.         $this->query = $params['query'];
  21.         else $this->query = null;
  22.  
  23.         $totalpages = parent::getArray($this->query);
  24.         $total = round(count($totalpages)/$this->perpage);
  25.  
  26.         $get['page'] = $_GET['page'];
  27.  
  28.         if(!empty($get['page']))
  29.         {
  30.             $this->pg = $get['page'];
  31.             if ($this->pg == '1')
  32.             {
  33.                 $this->start = '0';
  34.             }
  35.  
  36.             else
  37.  
  38.             {
  39.                 $this->start = ($this->pg*$this->perpage)-($this->perpage-1);
  40.             }
  41.         }
  42.         else
  43.         {
  44.             $this->pg = 1;
  45.             $this->start = 0;
  46.         }
  47.  
  48.         if ($get['page'] > $total)
  49.         {
  50.             $this->start = ($total*$this->perpage) - ($this->perpage-1);
  51.         }
  52.         $this-> data = parent::getArray($this->query."limit".$this->start.",".$this->perpage."");
  53.     }
  54.  
  55.     public function paginate()
  56.     {
  57.         $totalpages = parent::getArray($this->query);
  58.         $total = round(count($totalpages)/$this->perpage);
  59.  
  60.         $maxpage = $this->pg+$this->fluctuation;
  61.         $minpage = $this->pg-$this->fluctuation;
  62.  
  63.         if($this->pg < $this->fluctuation)
  64.         {
  65.             $minpage = 1;
  66.             $maxpage = $this->shortest;
  67.             $pageone = null;
  68.             $lastpage = null;
  69.         }
  70.  
  71.         if($maxpage > $total)
  72.         {
  73.         $maxpage = $total;
  74.         $lastpage = null;
  75.     }
  76.     if($minpage < 1)
  77.     {
  78.         $minpage = 1;
  79.     }
  80.  
  81.     if ($this->pg < $this->shortest)
  82.     {
  83.         $pageone = null;
  84.     }
  85.     else $pageone = 1;
  86.  
  87.     if ($this->pg > ($total-$this->shortest))
  88.     {
  89.         $lastpage = null;
  90.     }
  91.     else $lastpage = total;
  92.  
  93.     if(!empty($pageone))
  94.     {
  95.         $ret .= '<a style="text-decoration: none" href="'.SITE_PATH.'?page=1"><span class="paging">'.$pageone.'</span?</a>...';
  96.     }
  97.     for($i=$minpage; $i<=$maxpage; $i++)
  98.     {
  99.         if($this->pg ==$i)
  100.         {
  101.             $ret .= '<span class = "paging">'.$i.'</span>';
  102.         }
  103.         else $ret .= '<a style="text-decoration:none" href="'.SITE_PATH.'?pages='.$i.'"><span class="paging">'.$i.'</span></a>';
  104.     }
  105.     if(!empty($lastpage))
  106.     {
  107.         $ret .= '...<a style="text-decoration: none" href="'.SITE_PATH.'?page='.$lastpage.'"><span class="paging">'.$lastpage.'</span></a>';
  108.     }
  109.     $ret .= "</p>";
  110.  
  111.     echo $ret;
  112. }
  113. public function get_data()
  114. {
  115.     return $this->data;
  116. }
  117. ?>
  118.  

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,656
#2: Oct 16 '09

re: PHP error message


if you add the closing brace at the end the class will render ok. there seems to be an error in the parent class, though.

PS there’s an indenting space/tab missing from line 73 on
Newbie
 
Join Date: Oct 2009
Posts: 31
#3: Oct 16 '09

re: PHP error message


Hi thanks for the response,

I realised that id forgotten to add in my connection function.

Now thats its added im in a whole new world of pain as i now have an issue with this giving me "Fatal error, call to undefined method db::getArray
Expand|Select|Wrap|Line Numbers
  1.  $this-> data = parent::getArray($this->query."limit".$this->start.",".$this->perpage."");
heres the whole thing

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. class db {
  4.         // Possible Modules are as follows:
  5.         // DBX_MYSQL, DBX_ODBC, DBX_PGSQL, DBX_MSSQL, DBX_FBSQL, DBX_SYBASECT, DBX_OCI8, DBX_SQLITE
  6.         private $module = 'DBX_MYSQL'; 
  7.  
  8.         private $host = "localhost";
  9.         private $database = "university";
  10.         private $username = "***";
  11.         private $password = "***";
  12.  
  13.         private $link;
  14.         private $result;
  15.         public $sql;
  16.  
  17.         function __construct($database=""){
  18.                 if (!empty($database)){ $this->database = $database; }
  19.                 $this->link = dbx_connect($this->module,$this->host,$this->database,$this->username,$this->password);
  20.                 return $this->link;  // returns false if connection could not be made.
  21.         }
  22.  
  23.         function query($sql){
  24.                 if (!empty($sql)){
  25.                         $this->sql = $sql;
  26.                         $this->result = dbx_query($this->link,$sql,DBX_RESULT_UNBUFFERED);
  27.                         return $this->result;
  28.                 }else{
  29.                         return false;
  30.                 }
  31.         }
  32.  
  33.         function fetch($result=""){
  34.                 if (empty($result)){ $result = $this->result; }
  35.                 return dbx_fetch_row($result);
  36.         }
  37.  
  38.         function __destruct(){
  39.                 dbx_close($this->link);
  40.         }
  41. }
  42. class paginator extends db
  43. {
  44.     public $data;
  45.     public $query;
  46.     public $perpage;
  47.     public $shortest = 5;
  48.     public $fluctuation = 3;
  49.     public $pg;
  50.     public $start;
  51.  
  52.     public function __construct($params)
  53.     {
  54.         if(!empty($params['perpage']))
  55.         $this->perpage = $params['perpage'];
  56.         else $this->perpage = 10;
  57.  
  58.         if(!empty($params['query']))
  59.         $this->query = $params['query'];
  60.         else $this->query = null;
  61.  
  62.         $totalpages = parent::getArray($this->query);
  63.         $total = round(count($totalpages)/$this->perpage);
  64.  
  65.         $get['page'] = $_GET['page'];
  66.  
  67.         if(!empty($get['page']))
  68.         {
  69.             $this->pg = $get['page'];
  70.  
  71.             if ($this->pg == '1')
  72.             {
  73.                 $this->start = '0';
  74.             }
  75.  
  76.             else
  77.  
  78.             {
  79.                 $this->start = ($this->pg*$this->perpage)-($this->perpage-1);
  80.             }
  81.         }
  82.         else
  83.         {
  84.             $this->pg = 1;
  85.             $this->start = 0;
  86.         }
  87.  
  88.         if ($get['page'] > $total)
  89.         {
  90.             $this->start = ($total*$this->perpage) - ($this->perpage-1);
  91.         }
  92.         $this-> data = parent::getArray($this->query."limit".$this->start.",".$this->perpage."");
  93.     }
  94.  
  95.     public function paginate()
  96.     {
  97.         $totalpages = parent::getArray($this->query);
  98.         $total = round(count($totalpages)/$this->perpage);
  99.  
  100.         $maxpage = $this->pg+$this->fluctuation;
  101.         $minpage = $this->pg-$this->fluctuation;
  102.  
  103.         if($this->pg < $this->fluctuation)
  104.         {
  105.             $minpage = 1;
  106.             $maxpage = $this->shortest;
  107.             $pageone = null;
  108.             $lastpage = null;
  109.         }
  110.  
  111.         if($maxpage > $total)
  112.         {
  113.         $maxpage = $total;
  114.         $lastpage = null;
  115.     }
  116.     if($minpage < 1)
  117.     {
  118.         $minpage = 1;
  119.     }
  120.  
  121.     if ($this->pg < $this->shortest)
  122.     {
  123.         $pageone = null;
  124.     }
  125.     else $pageone = 1;
  126.  
  127.     if ($this->pg > ($total-$this->shortest))
  128.     {
  129.         $lastpage = null;
  130.     }
  131.     else $lastpage = total;
  132.  
  133.     if(!empty($pageone))
  134.     {
  135.         $ret .= '<a style="text-decoration: none" href="'.SITE_PATH.'?page=1"><span class="paging">'.$pageone.'</span></a>...';
  136.     }
  137.     for($i=$minpage; $i<=$maxpage; $i++)
  138.     {
  139.         if($this->pg ==$i)
  140.         {
  141.             $ret .= '<span class = "paging">'.$i.'</span>';
  142.         }
  143.         else $ret .= '<a style="text-decoration:none" href="'.SITE_PATH.'?pages='.$i.'"><span class="paging">'.$i.'</span></a>';
  144.     }
  145.     if(!empty($lastpage))
  146.     {
  147.         $ret .= '...<a style="text-decoration: none" href="'.SITE_PATH.'?page='.$lastpage.'"><span class="paging">'.$lastpage.'</span></a>';
  148.     }
  149.     $ret .= "</p>";
  150.  
  151.     echo $ret;
  152.     }
  153.  
  154. public function get_data()
  155. {
  156.     return $this->data;
  157. }
  158. }
  159. ?>
  160.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,656
#4: Oct 16 '09

re: PHP error message


Quote:

Originally Posted by whitep8 View Post

Now thats its added im in a whole new world of pain as i now have an issue with this giving me "Fatal error, call to undefined method db::getArray

Expand|Select|Wrap|Line Numbers
  1.  $this-> data = parent::getArray($this->query."limit".$this->start.",".$this->perpage."");

yupp, you don’t have a getArray() method at all.
Reply