3

In my codeIgniter project I have separate tables to each user. like, tbl_user1, tbl_user2, tbl_user3, tbl_user4, etc. this 1,2,3,4 are user id numbers.

after particular user logged in to the system, i need to access table which is related to user. (ex. for user 2, need to fetch data from tbl_user2 table).

I have session variable containing user id,

$uid=$this->session->userdata('uid');  //$uid=2 for **user 2**

how to use this with my model and controller,

ex. controller

$this->tbl_user('username'); //$this->tbl_user.$uid('username'); - not working

ex. model

 $this->db->select('tbl_user.$uid.*', false);  - //not working
    $this->db->from('tbl_user.$uid'); - //not working

please advice.

1 Answer 1

1

Controller:

$this->{'tbl_user' . $uid}('username');

model: Use double quote

$this->db->select("tbl_user.$uid.*", false);
$this->db->from("tbl_user.$uid");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.