Welcome Guest, Not a member yet? Register   Sign In
Can't use multiple FROM_UNIXTIME?
#1

[eluser]aquary[/eluser]
I have a problem trying to use multiple FROM_UNIXTIME in CodeIgniter. I want 2 types of date format so I can use the same function on different part. The problem part is:

Code:
$this->db->select('FROM_UNIXTIME(post_date, "%D %M, %Y") as full_date, news.*');
$this->db->select('FROM_UNIXTIME(post_date, "%D %M") as pdate');

At first, the select part was only 1 line, but I got database error when trying to execute it.

The error :
Code:
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 ') as pdate FROM (`site_news` news) WHERE newsID=00006' at line 1

SELECT FROM_UNIXTIME(`post_date`, "%D %M, %Y") as full_date, news.*, "%D %M") as pdate FROM (`site_news` news) WHERE newsID=00006

The code runs fine if I put only one FROM_UNIXTIME. I don't understand why the last FROM_UNIXTIME( dissappear from the query....

Any ideas? Thanks Smile
#2

[eluser]GSV Sleeper Service[/eluser]
try adding FALSE as a second parameter to $this->db->select().
from the manual
Quote:$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.




Theme © iAndrew 2016 - Forum software by © MyBB