Welcome Guest, Not a member yet? Register   Sign In
What is the best way for data in user section
#3

[eluser]Michal1[/eluser]
Thank you for your help.

I tried to do code that and still cannot get it work as I do not know how to do some things. Do you think you could help me?

This is me "site controller" which controlls displaying articles. Inside of it I have:

Code:
class Site extends Controller {
    
    function index()
    
    {
        
        $data=array();
        if ($query=$this->site_model->get_data()
        
        {
            $data['records']=$query;
            
        }
$this->load->view('site_view', $data);

}

Then I have "site" model which has function get_data

Code:
function get_data()
        {
    
    $this->db->order_by("id","desc");
    $query=$this->db->get('data');
    
    return $query->result();
}

So this all takes and display every article from database.


Then I have a controller "login" and inside of that is

Code:
class Login extends Controller {
    
    function index()
    
    {
        
        
        
        $this->load->view('login_view');   //this loads just a view with forms for username, password and submit button
    }
    
    function validate()
    
    {
        if ($query=$this->login_model->validate_login())
        
        {
        $data = array (
            
            'logged_in'=> true
            
                )    ;
                
            $this->session->set_userdata($data);    
            redirect('site');   //if succes redirect to site controller
        }
        
        else
            {
                $this->index();  // if not reload login form
            }
        
        }
        
        
    
    
    
}

And then the last one is login_model

Code:
function validate_login()
    
    {
    
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', $this->input->post('password'));
        $query= $this->db->get('users');
        
        if ($query->num_rows==1)
        
        {
            
            return true;
        }
        
        
        
    }

And now I want to do that when certain user is logged in I will store his uniquate field from its database called "id_users"

and then I would just probably need to reedit my function in site_model

from
Code:
function get_data()
        {
    
    $this->db->order_by("id","desc");
    $query=$this->db->get('data');
    
    return $query->result();
}

to something different, probably using where. So something like

Code:
$this->db->where('user_id, $id_users);
$this->db->order_by("id","desc");
    $query=$this->db->get('data');

So the main problem for is how to insert certain user "id" which is field in database to $id_users and then use it in site_model for this $this->db->where('user_id, $id_users);

Thank you very much and I hope this makes sense


Messages In This Thread
What is the best way for data in user section - by El Forum - 03-06-2011, 05:10 AM
What is the best way for data in user section - by El Forum - 03-06-2011, 05:20 AM
What is the best way for data in user section - by El Forum - 03-06-2011, 11:59 AM
What is the best way for data in user section - by El Forum - 03-06-2011, 12:29 PM
What is the best way for data in user section - by El Forum - 03-06-2011, 02:07 PM
What is the best way for data in user section - by El Forum - 03-07-2011, 01:24 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:25 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:34 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:36 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:45 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:48 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:51 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:53 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 02:58 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 03:01 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 03:01 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 03:04 AM
What is the best way for data in user section - by El Forum - 03-07-2011, 03:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB