Jump to content

Db class update to update every other id except one


prestashop_newuser

Recommended Posts

I am a newbie in Prestashop. I am doing a small module. In that module I want to update a table. But my condition is like this it will update those rows whose id is not 3. So for me my table is like this

id name status
1     test1   0
2    test4    0
3    test5    1
4    test9    0
5    test12   0
6    test25   0

So as per DB classes I made my query like this

$id = 3;
Db::getInstance()->update('table', array('status'=>'1'), 'id != '.$id );

also I have tried

Db::getInstance()->update('table', array('status'=>'1'), 'id <> '.$id );

But its not working. So can someone kindly tell me how to fix this. Any help and suggestions will be really appreciable. Thanks

Edited by prestashop_newuser (see edit history)
Link to comment
Share on other sites

What you have done looks correct, but 'not working' isn't enough information to go by.

 

If you are having trouble using the update function, then just execute either of these queries

Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'table SET `status` = 1 WHERE `id` != '. (int)$id);
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'table SET `status` = 1 WHERE `id` <> '. (int)$id);

Link to comment
Share on other sites

 

What you have done looks correct, but 'not working' isn't enough information to go by.

 

If you are having trouble using the update function, then just execute either of these queries

Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'table SET `status` = 1 WHERE `id` != '. (int)$id);
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'table SET `status` = 1 WHERE `id` <> '. (int)$id);

Nope this is not working. I have used your suggested code and it showed error like this

mymodule (parse error in /modules/mymodule/mymodule.php)

When I removing this line of code.Everything seems to be okay.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...