Pass the string in the request without using quotes ''

I have this code for the request:

$conditions[]=array('codiceBiblio IN (?)'=> $tot); 

Where $ tot is a string (for example: 2345,5657,4565,5678).

In this case, the request will look like this:

 SELECT [...] WHERE codiceBiblio IN ('2345,5657,4565,5678') 

But he will return only the first record.

So it could be:

 SELECT [...] WHERE codiceBiblio IN (2345,5657,4565,5678) 

How can i do this?


How to create a request

I have this code for the request:

 // General Query $conditions = array( 'editore LIKE' => "%$e%", 'titolo LIKE' => "%$t%" ); 

And I populate $ conditions with custom options, for example:

 if ($anno&&$anno2) $conditions[] = array('anno BETWEEN ? AND ?' => array($anno,$anno2)); if (isset($menu)&&$menu!='') $conditions[]=array('classe LIKE' => "%$menu%"); 
+4
source share
2 answers

Just use an array and omit the IN() clause. The manual ( Comprehensive search terms ) provides an example:

 array('Company.status' => array('inactive', 'suspended')) 

... which creates the following SQL:

 `Company`.`status` IN ('inactive', 'suspended') 

If $tot is a string like 2345,5657,4565,5678 , you need to detonate () first.

Disclaimer: This works in Cake 2, not sure about 1.2.

+8
source

Álvaro G. Vicario's suggestion is correct, but you can also do this:

 $conditions[]=array('codiceBiblio IN (' . $tot . ')'); 
+1
source

All Articles