Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Sql function on a query ?
#1

[eluser]raïs[/eluser]
Hi.

I'm trying for a while, and desperatly to use an sql function on a simple query.
The query I would like to execute ( tested on mysql )

Code:
SELECT * FROM `billet` WHERE date_creation > sysdate() - 2

With Codeigniter, I've tried :

Code:
$this->db->query("SELECT * FROM `billet` WHERE date_creation > sysdate() -2");

but the result is incorrect.
Some one could help me please ?
#2

[eluser]InsiteFX[/eluser]
Not tested by give this a try!

Code:
// you may need to play with this! Not Tested...
$date = sysdate()-2;

$data = array('date_creation >' => $date);

$this->db->where($data);
$query = $this->db->get('billet');

InsiteFX
#3

[eluser]raïs[/eluser]
Thanks for your proposition but fortunatly, it does not work. :/

The error code :

Code:
Fatal error: Call to undefined function sysdate() in ....

an idea ?
#4

[eluser]intractve[/eluser]
sysdate is not a php function. so that won't work as is.

You could try,

Code:
$date = date('Y-m-d',strtotime('-2 Days'));

$data = array('date_creation >' => $date);

$this->db->where($data);
$query = $this->db->get('billet');

Also, SQL functions do work inside the query;

Code:
$this->db->query("SELECT SUM(`field1`) as 'total' FROM `table`");  //This Works (SUM is a mysql function.)
#5

[eluser]raïs[/eluser]
Probleme solved Smile

Thanks brothers !




Theme © iAndrew 2016 - Forum software by © MyBB