CodeIgniter Forums

Full Version: How not to get selected data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have my code below I would like to be able to use 'users.*' to be able to get the users data how ever is there a way in select not to get the password but gets the all of other data.

Currently it gets all users data include password. I don't want it do get password.

PHP Code:
public function get_user($column ''$id '')
{
    
$this->db->select('users.*, user_groups.*');
    
$this->db->from($this->db->dbprefix 'users''LEFT');
    
$this->db->join('user_groups''user_groups.user_group_id = users.user_group_id''LEFT');
    
$this->db->where("users.user_id"$id);
    
$user_query $this->db->get();

    return 
$user_query->row_array();
        

You would need to specify the fields something like below.

Code:
SELECT tbl_a.column1 , tbl_a.column2
      tbl_b.column1 , tbl_b.column2
FROM   tbl_a , tbl_b
WHERE  tbl_a.commonfield=tbl_b.commonfield
(07-06-2017, 03:07 AM)InsiteFX Wrote: [ -> ]You would need to specify the fields something like below.

Code:
SELECT tbl_a.column1 , tbl_a.column2
      tbl_b.column1 , tbl_b.column2
FROM   tbl_a , tbl_b
WHERE  tbl_a.commonfield=tbl_b.commonfield

I  know all that was wondering if just can use users.* only and have a some thing in there not to get password other wise I will just have to do it the long way.
There is no "reverse" select that I know of.
It is recommended to always use the field names. Its good practice NOT to use the * in the select.
The * is more for the newbie programmers that dont know any better. (There are of course exceptions where * is perfectly legitimate)
You could always just unset the item:

PHP Code:
$result $user_query->row_array();
unset(
$result['user_password']);
return 
$result

However, I would prefer to just select the columns I need rather than do the above.
(07-06-2017, 10:12 AM)PaulD Wrote: [ -> ]You could always just unset the item:

PHP Code:
$result $user_query->row_array();
unset(
$result['user_password']);
return 
$result

However, I would prefer to just select the columns I need rather than do the above.

Thanks for that.
Strictly speaking, who cares if password is return, it is "encrypted" in db, correct?