0

I'm using Nette Framework and I have this commands in action:

    $id = is_array($id) ? implode(', ', $id) : $id;
    $this->database->table('manufacturing')->where('id', $id)->update(array('trash' => '1'));

When I select 4 rows in my Grid and call this action to delete items, it will generate this SQL code:

UPDATE `manufacturing` 
SET `trash`='1' 
WHERE (`id` = '31, 32, 33, 34')

But I need code like this to update all rows:

UPDATE `manufacturing`
SET `trash` = '1'
WHERE ((`id` = '31') OR (`id` = '32') OR (`id` = '33') OR (`id` = '34'));

Is possible to do with implode function? Thank you.

edit: when I made this:

$id = is_array($id) ? implode(' "OR" ', $id) : $id;

it will do this:

UPDATE `manufacturing` 
SET `trash`='1' 
WHERE (`id` = '31 \"OR\" 32 \"OR\" 33 \"OR\" 34')
1
  • 2
    I'm not familiar w/ Nette, but I think you want to look for an option or alternative to ->where() that allows you to do an IN clause instead of = Commented Jan 28, 2015 at 22:37

1 Answer 1

5

you can directly pass the array in the where function, it will be transformed to a id IN (1,2,3,xxx) automaticaly.

Refs : http://doc.nette.org/en/2.2/database-selection#toc-filtering

Sign up to request clarification or add additional context in comments.

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.