Welcome Guest, Not a member yet? Register   Sign In
DB class within static function
#1

[eluser]Unknown[/eluser]
Hey guys. I am new to code igniter. Now, What i am trying to do is use CI database class within a static function, and i am getting the following error:

Fatal error: Using $this when not in object context in E:\webserv\prj\selector\system\application\controllers\albums.php on line 17
Code:
<?php
    class Albums extends Controller
    {    
    private $eventinfo_qry;
        function Albums()
        {  
            parent::__construct();
            $this->load->database();
        }
        
        function show()
        {
              
        }
        
        public static function albumInfo(array $userevents){
            foreach($userevents as $event)
            {
                $eventinfo_qry=$this->db->query("SELECT * FROM sl_events WHERE eventid=".$event[0]['eventid']);
                return  $eventinfo_qry->result_array();
            }
        }

        public static function albumPhotosNum(array $event){
                $photonum_qry=$this->db->query("SELECT count(*) FROM sl_imgs WHERE eventid=".$event[0]['eventid']);
                return $photonum_qry->num_rows()." Photo";      
              
        }
        
        function index()
        {
            $usreventstatus_qry=$this->db->query("SELECT * FROM sl_usereventstatus WHERE userid='1' AND status='yes'");  
            if($usreventstatus_qry->result_array())
            {
            $data['userevents']=$usreventstatus_qry->result_array();
            $data['noalbum']=FALSE;
            }else{
            $data['noalbum']=TRUE;
            }
            $data['title']="User Album";
            
            $this->load->view('albums_view',$data);
        }
    }
?>

Is there any way to make it work?
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB