0

I want to retrieve multiples values from a field. the code I am using this this

$conditions = array('Tag.name'=>$compare);//$compare = array('value1', 'value2',..);
$values = $this->find('all', array('conditions' => $conditions));

But It keeps coming out like this

    SELECT `Tag`.`id`, `Tag`.`name`, `Tag`.`count` FROM `tags` AS `Tag` WHERE `Tag`.`name` IN ('tag2', ' tag1', ' one tag') 

Problem is it only retrieves the first value given. instead of all the values . How do I get it to select all the values in the array.

2
  • Is that the entire query that it is generating? Commented Nov 6, 2009 at 15:51
  • Are you sure there are 'tag2', ' tag1', ' one tag' tags in your tags table? Paste the var_dump($values); print out back here. Commented Nov 6, 2009 at 20:32

1 Answer 1

2

What version of Cake are you using?

But the main thing is that your conditions needs to be in a fields array.

find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'fields' => array('name', 'email'),
'order' => 'field3 DESC',
'recursive' => 2,
'group' => 'type'
));

Ref, Model::find() API Docs

The reason your query is not working is that you need to move it into that pattern..

So your query would be,

$compare = array('value1', 'value2');
$values = $this->Model->find('all', array('fields' => $compare));

Not sure on your example if you meant to omit it, but always best to include the model you are running the find against :)

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.