Bind with commas

Bind with commas

AlchetecAlchetec Posts: 14Questions: 5Answers: 0
edited February 2016 in Editor

I have the following code:

$q->where( 'unit', '(:units)', 'IN', false );
$q->bind( ':units', '4210, 4211' );

If I have 4210 it works but the ',' seems to be a problem. I tried using '\,' to escape the ',' but that still doesn't work.

Note: $q->where( 'unit', '(4210, 4211)', 'IN', false ); works.

Any guidance? Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    Yes, unfortunately that wouldn't work since it would effectively cope out like: WHERE unit IN ('4210, 4211') (note the string quotes).

    I've just had a look at the PHP documentation and I don't actually see a way of doing what you want with the PDO methods. What you would probably need to do is use or_where and loop over your array of values. Using IN is probably only useful if you get the results from an inner SELECT.

    Allan

  • AlchetecAlchetec Posts: 14Questions: 5Answers: 0

    That worked. So others see the complete solution, this is how I changed things:

    $q->or_where( function ( $r ) {
       global $units;
       foreach ($units as $unit) {
          $r->or_where( 'unit', $unit );
       }
    } );
    
This discussion has been closed.