CodeIgniter Forums
[Solved] Get data from database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: [Solved] Get data from database (/showthread.php?tid=62292)



[Solved] Get data from database - wolfgang1983 - 06-29-2015

On my user_mail table I have two columns called from_user and to_user.

[Image: user_mail.png]

When I log on as test_user I can view the message fine. But when I log on as demo I can not view the message from test_user.

When log in I would like to be able to display messages. So If I login as demo for example I would be able to see any messages from test_user and so on. and if I log on as test_user I would be able to see messages from demo

Currently my model only able to make it from user can view message trying to make it so can do with out session->userdata

PHP Code:
public function get_user_mail() {
$this->db->where('from_user'$this->session->userdata('username'));
$query $this->db->get('user_mail');
if (
$query->num_rows() > 0) {
return 
$query->result_array();
} else {
return 
false;
}


What would be the best solution any suggestions?


RE: [Question] Get data from database - wolfgang1983 - 06-29-2015

I think I have worked it out using or_where in function seemed to do the trick


PHP Code:
public function get_user_mail() {

//$this->db->where('from_user', $this->session->userdata('username'));
$this->db->or_where('to_user'$this->session->userdata('username'));

$query $this->db->get('user_mail');

if (
$query->num_rows() > 0) {
return 
$query->result_array();
} else {
return 
false;
}