I have this code for the query:
$conditions[]=array('codiceBiblio IN (?)'=> $tot);
Where $tot is a string (eg: 2345,5657,4565,5678).
In this case, the query will be:
SELECT [...] WHERE codiceBiblio IN ('2345,5657,4565,5678')
But it will returns just the first record.
So it sould be:
SELECT [...] WHERE codiceBiblio IN (2345,5657,4565,5678)
How can I do it?
How the query is built
I have this code for a query:
// General Query
$conditions = array(
'editore LIKE' => "%$e%",
'titolo LIKE' => "%$t%"
);
And I fill up $conditions with user's choices, for example:
if ($anno&&$anno2)
$conditions[] = array('anno BETWEEN ? AND ?' => array($anno,$anno2));
if (isset($menu)&&$menu!='')
$conditions[]=array('classe LIKE' => "%$menu%");
Just use an array and omit the IN()
clause. The manual (Complex Find Conditions) provides this example:
array('Company.status' => array('inactive', 'suspended'))
... which produces the following SQL:
`Company`.`status` IN ('inactive', 'suspended')
If $tot
is a string like 2345,5657,4565,5678
you'll need to explode() it first.
Disclaimer: This works in Cake 2, not sure about 1.2.
Álvaro G. Vicario's suggestion is the correct one, but you can also do this:
$conditions[]=array('codiceBiblio IN (' . $tot . ')');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With