Welcome Guest, Not a member yet? Register   Sign In
database modeling for a friend list
#11

[eluser]bluepicaso[/eluser]
Thank you erik.brannstrom. that was quit fast.. Thanks a lot. i need more suggestions though.

Thanx again
#12

[eluser]bluepicaso[/eluser]
finally i have changed my database to Many to many relations. Hope it works
#13

[eluser]bluepicaso[/eluser]
ok here is a problem

the code works fine. But results are unexpected.

Code:
function getUserFrnds($user_id, $num, $offset)
    {
        $this->db->select('*');
        $this->db->from('frnds');
        $this->db->where('frnds.user_id', $user_id);
        $this->db->or_where('frnds.frnd_is', $user_id);
        $this->db->join('user', 'frnds.frnd_is = user.user_id', 'left');
        $this->db->join('user usr', 'frnds.user_id = usr.user_id', 'left');
        $this->db->join('country', 'user.cntry = country.cntry_id');
        $this->db->limit($num, $offset);
        $query = $this->db->get()->result_array();
        foreach($query as $row)
        {
            $data[] = $row;
        }
        return $data;
        $this->db->close();
    }

the result i get is this.

Though the record is different but displays same user details.
Pleas help me. Its due to some unlogical active record I'm calling.
please help


Quote:Array
(
[0] => Array
(
[frnd_id] => 8
[user_id] => 9
[frnd_is] => 15
[status] =>
[username] => bluepicaso
[email] => [email protected]
[pwd] => b68283b19320106c5a12efdc35a39e5c
[display_name] => misha
[about_me] => Hey all How r u?
[thumb] => uploads/user/99_thumb.jpg
[image] => uploads/user/99.jpg
[location] => Delhi
[cntry] => Brazil
[is_new] => 1
[cntry_id] => 32
[cntry_sm] => BR
)

[1] => Array
(
[frnd_id] => 11
[user_id] => 9
[frnd_is] => 17
[status] =>
[username] => bluepicaso
[email] => [email protected]
[pwd] => b68283b19320106c5a12efdc35a39e5c
[display_name] => misha
[about_me] => Hey all How r u?
[thumb] => uploads/user/99_thumb.jpg
[image] => uploads/user/99.jpg
[location] => Delhi
[cntry] => Angola
[is_new] => 1
[cntry_id] => 8
[cntry_sm] => AO
)

[2] => Array
(
[frnd_id] => 9
[user_id] => 9
[frnd_is] => 16
[status] =>
[username] => bluepicaso
[email] => [email protected]
[pwd] => b68283b19320106c5a12efdc35a39e5c
[display_name] => misha
[about_me] => Hey all How r u?
[thumb] => uploads/user/99_thumb.jpg
[image] => uploads/user/99.jpg
[location] => Delhi
[cntry] => Armenia
[is_new] => 1
[cntry_id] => 13
[cntry_sm] => AM
)

)

I want to show friends of user whome the user follows and the ones who follow this user.

Please help

i want to display each friends name but it displays current user in each record.
#14

[eluser]bluepicaso[/eluser]
Please help guys. Please
#15

[eluser]Buso[/eluser]
[quote author="PDP" date="1239962060"][quote author="slowgary" date="1239954888"]What's the big deal? I write code for planes all the time. A few Boeing planes are using code that I wrote. And so far, only a few crashesSmile[/quote]

I'm never riding a Boeing from now on Wink[/quote]
ahahahaha :lol:
#16

[eluser]bluepicaso[/eluser]
Please help rather than laughing
#17

[eluser]bluepicaso[/eluser]
I found the Solution

here is the code for the model

Code:
function getUserFrnds($user_id, $num, $offset)
        {
            $this->db->select('*');
            $this->db->from('frnds');
            $this->db->where('frnds.usr_id', $user_id);
            $this->db->join('user', 'frnds.frnd_is = user.user_id', 'left');
            $this->db->join('country', 'user.cntry = country.cntry_id');
            $this->db->limit($num, $offset);
            $this->db->orderby('user.display_name');
            $query = $this->db->get()->result_array();
            foreach($query as $row)
            {
                if($row['user_id'] != $user_id)
                {
                    $data[] = $row;
                }
            }
            
            $this->db->select('*');
            $this->db->from('frnds');
            $this->db->where('frnds.frnd_is', $user_id);
            $this->db->join('user', 'frnds.frnd_is = user.user_id', 'left');
            $this->db->join('country', 'user.cntry = country.cntry_id');
            $this->db->limit($num, $offset);
            $this->db->orderby('user.display_name');
            $query2 = $this->db->get()->result_array();
            foreach($query2 as $row)
            {
                if($row['user_id'] != $user_id)
                {
                    $data[] = $row;
                }
            }
            

            
            //echo "<pre>";
            //print_r($data);
            //echo "</pre>";
            return $data;
            $this->db->close();
        }

generated results as expected.

Thank you JAY
#18

[eluser]bluepicaso[/eluser]
what was that




Theme © iAndrew 2016 - Forum software by © MyBB