Welcome Guest, Not a member yet? Register   Sign In
[Solved] Get data from database
#1

(This post was last modified: 06-29-2015, 04:23 AM by wolfgang1983.)

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?
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

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;
}

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB