Any tips on how to use Mapper with SQL IN() function?

40 views
Skip to first unread message

ethanpil

unread,
Dec 4, 2014, 2:10:56 PM12/4/14
to f3-fra...@googlegroups.com
Typical binding doesnt work with the IN() function..

$catalog->find( array('ITEM_NO IN(?)', $alternatives));

Any ideas on how to keep this query within the mapper?

ikkez

unread,
Dec 4, 2014, 2:45:15 PM12/4/14
to f3-fra...@googlegroups.com
$catalog->find( array('ITEM_NO IN(?,?,?)', $alternatives[0],$alternatives[1],$alternatives[2]));

this should work

ethanpil

unread,
Dec 4, 2014, 3:41:06 PM12/4/14
to f3-fra...@googlegroups.com
Ahh, very nice... but what if, of course, I have a dynamic number of parameters... :)

Achille D'Aniello

unread,
Dec 4, 2014, 4:59:56 PM12/4/14
to f3-fra...@googlegroups.com
Hi,
in a similar case i used something like this:

$catalog->find( array('ITEM_NO IN(?)', implode(",", my_array_of_alternatives )));

Naturally, if your array of values isn't only numeric, you need to adapt the first parameter of implode.

I don't know if is the "right" mode, but i hope this can help you
Reply all
Reply to author
Forward
0 new messages