1

Using the zend framework i have used a query,having a IN clause,this is my query

       $select->where('p.brandid  IN (?)',$details[brand]);

in the above query, $details[brand] has a value like this array(1,2,3) .

Actually the query has to return all the values which are all related to this array(1,2,3).

But my query is returning the result related to the first value present in the above array(1,2,3).ie 1 alone other 2,3 is not considered.

when i print this query it shows like this

             [where] => Array
               (
                [0] => (p.brandid  IN ('1,2,3'))
              )

Can anyone show me what is the mistake i have made or solution for this..

4 Answers 4

1

This is because your query is getting formed wrongly p.brandid IN ('1,2,3') instead of p.brandid IN (1,2,3) you can try using implode function in php

$select->where('p.brandid  IN (?)',implode(",",$details[brand]));
Sign up to request clarification or add additional context in comments.

Comments

1

Just small research, because I have the same problem.

I am not sure what version of Zend do you use. But solution provided by @Omesh doesn't work with my version 1.12.

In my case it is absolutely opposite explode solution:

$select->where('p.brandid  IN (?)', explode(',',$details[brand]));

Probably it depends on the type of $details['brand']. In my case I have string like 555,666,777,877. But even if you have array there. That is strange if Zend accept in your case string (result of implode) and does not accept array. And in my case it does not accept string but accept array.

Comments

0

You can modify this according to Zend framwork

locate(concat(',',$details[brand],','),concat(',',p.brandid,','))>0

Comments

0

Just use

$select->where->in('field_name', $your_simple_array);

If you using where() function with something criteria before, like

$select->where(['field_name' => $value]);

just use the first one after it, like

$select->where(['field_name' => $value]);
$select->where->in('field_name', $your_simple_array);

Always remember to use where not as a function where(), but just as a keyword.

This is valid and tested by me in the following context:

$select = $this->tableGateway->getSql()->select()->where(['field1' => $v1, 'field2' => $v2]);
$select->where->in('field_name', ['v1', 'v2', 'v3']);

That is, using these libraries in the beginning of the model class:

use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Where;

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.