2

I have an array which I want to use in a query:

Array ( [0] => stdClass Object ( [followee] => 267,269,270,271,272,273,275,276,277,278,279 ) )

I'm not sure why it returns the message:

Object of class stdClass could not be converted to string.

Controller:

$data['activity'] = $this->home_model->activity($followID);

Model:

function activity($followID)
{
    $query_str = 'SELECT DISTINCT name
                    FROM place
                    WHERE userid IN ("'. implode('","', $followID) .'")';

$query = $this->db->query($query_str);
2
  • Did you check the dump? var_dump( $this->home_model->activity($followID) ); Commented Jul 5, 2012 at 6:50
  • It's returning this : bool(false) Commented Jul 5, 2012 at 6:55

2 Answers 2

2

Try $your_array[0]->followee.

Sign up to request clarification or add additional context in comments.

6 Comments

Message: implode() [function.implode]: Invalid arguments passed WHERE userid IN ("'. implode('","', $followID[0]->followee) .'")';
function activity($followID[0]->followee) - Parse error: syntax error, unexpected '[', expecting ')'
Which variable is Array ( [0] => stdClass Object ( [followee] => 267,269,270,271,272,273,275,276,277,278,279 ) ) ?
And this array means $your_array, not $followID.
$followIDis Array ( [0] => stdClass Object ( [followee] => 267,269,270,271,272,273,275,276,277,278,279 ) )
|
0

Well, you have an object in you variable and you don't want to convert that.

The right way, to access the variable would be creating a function inside your class like this:

public function getFollowee() {
  return $this -> followee;
}

And the way to access it:

function activity() {
  $query_str = 'SELECT DISTINCT name FROM place WHERE userid IN ( ' . $stdClass -> getFollowee() . ')';
  $query = $this -> db -> query( $query_str );
}

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.