I've got a timestamp in my database with the value: 2011-10-05 16:06:48
which is bigger than the $start
variable (2011-10-04 13:02:34
) I have defined yet when I run the query I get an error message.
function getgeneration() {
$period = '1 month';
$siteid = 1;
$start = '2011-10-04 13:02:34';
$value = $this->GetOffset();
$this->db->select("esolar + $value AS Esolar")
->from('calcdata')
->where('siteid', $siteid)
->where("time > $start");
$query = $this->db->get()->result_array();
$Esolar1 = $query[0]['Esolar'];
echo $Esolar1;
return $Esolar1;
}
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13:02:34' at line 4
SELECT esolar + 3 AS Esolar FROM (calcdata) WHERE
siteid
= 1 ANDtime
> 2011-10-04 13:02:34Filename: /var/www/test/models/blog_model.php
Line Number: 220
Is this a common problem with timestamps?
It seems like you need to put quotes around the timestamp such as:
SELECT esolar + 3 AS Esolar FROM (calcdata) WHERE siteid = '1' AND time > '2011-10-04 13:02:34'
i think you just need to change
->where("time > $start");
in
->where("time > '$start'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With