Codeigniter - Use mysql column ID to grab specific data from the columns of that row? or maybe grab things from session?
I've just completed my user signup and login. When a user signups they are automatically logged in and when they reach the members area their post data first name and last name is taken from the session and echoed into the membe开发者_运维百科r area.
I wish to achieve this with my login but because the only post data created during login is "Email" and "Password" I can't grab first name and last name from the session and echo it because it doesn't exist.
Is there a way I can use the users "id" to grab info from specific columns of their row in the database?
e.g. user id of user that logged in to grab their "first name" and "last name" so I can echo it to the members area so they see this when they log in?
You can use CI's active record database pattern, read it up here
e.g.
$dbResult = $this->db->get_where('users', array( 'id' => $id ));
foreach($dbResult as $row)
{
echo $row->name;
}
$this->db->select('first_name, last_name');
$this->db->where('email', $this->session->userdata('email'));
$query = $this->db->get('user');
if ($query) {
foreach ($query->result() as $row)
{
echo $row->first_name . ' ' . $row->last_name;
This is worked for me.. but I don't want all of this in my view file.. So I'm going to move it.
精彩评论