HI,
I have this query which runs perfect on plain sql (phpmyadmin etc) :
Code:
SELECT
MONTHNAME (itd.DateOfshippment) AS Month
,COUNT(itm.Name) AS Operations
FROM ImportsMaster itm
INNER JOIN ImportsDetails itd on itm.ID = itd.IDMSTR
WHERE itd.Market IS NOT NULL
AND itm.Trader LIKE "%TEXT%"
AND itd.DateOfshippment between :start and :end
GROUP BY MONTH(itd.DateOfshippment)
Now I'm trying to do the same in ci (3) but I need to pass start and end variables
from post data, I have the following code in my model :
Code:
Public function get_results () {
$sql = "SELECT
MONTHNAME (itd.DateOfshippment) AS Month
,COUNT(itm.Name) AS Operations
FROM ImportsMaster itm
INNER JOIN ImportsDetails itd on itm.ID = itd.IDMSTR
WHERE itd.Market IS NOT NULL
AND itm.Trader LIKE "%TEXT%"
AND itd.DateOfshippment between :start: and :end:
GROUP BY MONTH(itd.DateOfshippment)"
Code:
$this->db->query($sql, [
'start' => $this->input->post('start'),
'end' => $this->input->post('end')
]);
}
According to documentation I need to enclose the named variables in colons but they're not
getting replaced by the actual data coming from the post data (which I can see if I echo the relevant named variable) .
I tried just to be sure to hard code the data in the code to check like this in the model :
Code:
$this->db->query($sql, [
'start' => '2021-01-01',
'end' => '2021-03-30' ]);
But it also doesn't get replaced so there must be something else I'm missing here but I can't figure out what.
Maybe I need to escape the named variables somehow but I have tried escaping them with single quotes or ` ` but
no change . I tried to use active record also but I cant make a proper query like the one I already have here.
George