CodeIgniter Forums
How not to get selected data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How not to get selected data (/thread-68404.html)



How not to get selected data - wolfgang1983 - 07-06-2017

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();
        




RE: How not to get selected data - InsiteFX - 07-06-2017

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



RE: How not to get selected data - wolfgang1983 - 07-06-2017

(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.


RE: How not to get selected data - rtenny - 07-06-2017

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)


RE: How not to get selected data - PaulD - 07-06-2017

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.


RE: How not to get selected data - wolfgang1983 - 07-06-2017

(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.


RE: How not to get selected data - karman - 07-06-2017

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