[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