Search code examples
phpimpresspages

ImpressPages 4.x database where condition with greater or less than


How can i use greater or less than in sql where conditions (<, >, <=, >=) on ImpressPages 4.x. I tried something like following but i got error on ipDb()->update() and ipDb()->delete() functions:

ipDb()->delete('Persons', array('age <=' => 18));

ipDb()->delete('Persons', array('age >' => 80));

ipDb()->delete('Persons', array('age <' => 25));

ipDb()->delete('Persons', array('age >=' => 41));

The Error:

Column not found: 1054 Unknown column 'age <=' in 'where clause'' in


Solution

  • ipDb() provides you very nice methods to cover 90% of your taks. But they don't cover all 100%. If you need to do the join or anything else more complex, use ipDb()->execute($sql, $paremters). This way you can execute any kind of query.

    In your particular case, ImpressPages has sqlMinAge and sqlMaxAge functions that may suit your case http://www.impresspages.org/docs/class-ip-db. If not, use raw SQL and ipDb()->execute method.