Welcome Guest, Not a member yet? Register   Sign In
Best way of retrieving primary key
#11

[eluser]jeremydt[/eluser]
Wow, that was really easy! Thanks a lot! I had no idea that you could actually do that; but now I read your code, it makes sense because it retrieves the row and assigns it to $q on line 5.
#12

[eluser]jeremydt[/eluser]
Well, I tested that code but it wouldn't work for me. I got the code below to work... is there too much redundant code?

Code:
function validate() {
        
        $this->db->where('user_username', $this->input->post('username'));
        $this->db->where('user_password', md5($this->input->post('password')));
        $q = $this->db->get('user');
        
        foreach ($q->result() as $row) {
            $username = $row->user_username;
            $userid = $row->user_id;
        }        
        
        if($q->num_rows == 1) {
            $data = array(
                'is_logged_in' => true,
                'userid' => $userid,
                'username' => $username
            );
            
            $this->session->set_userdata($data);
            return true;
        }
    }
#13

[eluser]Alexandru M.[/eluser]
Its not really about redundant code especially if you will have say 1k visitors / day , the most important thing is that the code should be readable , because in 2-3 months you'll forget what your logic was when you designed that controller or model .

Just try to keep the queries number low (in the above post you have just one) and it should be ok.




Theme © iAndrew 2016 - Forum software by © MyBB