0

I have created a class named as MEMBERS. In this class I have declared an array as a member variable.

class member
{
public $arr_connections;
function connections($id)
{
    $query = mysql_query("Select * from connections where user_id = '$id'");
    while($info = mysql_fetch_array($query))
    {
        $arr_connections[] = $info['connection_id'];
    }

}
}

Then I have created an object of this class as follow

 $user = new member();

After this I am calling the function as

$user->connections($user->id);

Next I am displaying the array

foreach($user->arr_connections as $mem_id)
{
            echo $mem_id;
            $person = new member($mem_id);
            echo "<a href = 'profile.php?id=$person->id'><img src = '$person->display_picture'/ width = 30 height = 30></a>";
}

This is not working. I guess my method is wrong. Some constructor was required. But I have to do this without constructor. Any suggestions?

1 Answer 1

3

You're not assigning it to the class property, because you're missing $this->. Change it into this and it should work for you:

$this->arr_connections[] = $info['connection_id'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.