CodeIgniter Forums
Calculate 2 fields with Active records - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Calculate 2 fields with Active records (/showthread.php?tid=69155)



Calculate 2 fields with Active records - manhvt - 10-14-2017

I have a table with fields
[Image: Rz9ByFZ_RUGgBsAsGxTaiA.png]

I want to looking for some records expired date in 6days.
today - test_time (created date) < duration - 6 days

My code don't work
Code:
$this->db->select("test.*");

$this->db->from('test');

$current_time = time();
$pre7day = $current_time - 7*60*60*24;
$next7day = $current_time + 7*60*60*24;
$this->db->where("duration * con <=", $next7day);
return $this->db->get();
This is a error:
Quote:Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '`con` <= 1508605807' at line 3

SELECT `ospos_test`.*FROM `ospos_test`WHERE `duration *` `con` <= 1508605807

Filename: vendor/codeigniter/framework/system/database/DB_driver.php

Line Number: 691

Please help me.

Thanks.
ho


RE: Calculate 2 fields with Active records - Kaosweaver - 10-16-2017

Try:
PHP Code:
$this->db->where("(duration * con) <="$next7day);