Welcome Guest, Not a member yet? Register   Sign In
Named variables in sql query
#5

(06-26-2021, 05:41 AM)InsiteFX Wrote: Try this one, no time to test right now busy.
You need to pass in the start and end strings for the dates to search.
PHP Code:
$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);'


Just tested this also , not working either  here is my full code in the model :

Code:
            $sql = 'SELECT
            MONTHNAME (`itd`.`DateOfshippment`) AS `Months`,
            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 "{$trader}"
            AND `itd`.`DateOfshippment` between "{$start}" and "{$end}"
            GROUP BY MONTH(`itd`.`DateOfshippment`)';
            $this->db->query($sql, [
                'start' => $this->input->post('start'),
                'end' => $this->input->post('end'),
                'trader' => $this->input->post('trader')
            ]);

I've tried your suggestions as well as numerous other  ones , the blinded values are not getting replaced
no matter what .
Also the named bindings documentation seems to be referencing a very old version of codeigniter . In the query builder
class I can only find the documentation about bindings which is very different .
Anyway I can't be the only one here with a similar problem , nobody else in here ever wanted to create a dynamic query using
raw sql ? Some other similar queries I've managed to convert to  query builder but this one uses MONTHNAME and COUNT
to return some values which I haven't figure out yet if I can do in a single query as in raw sql.
Reply


Messages In This Thread
Named variables in sql query - by stepgr - 06-26-2021, 01:03 AM
RE: Named variables in sql query - by InsiteFX - 06-26-2021, 01:51 AM
RE: Named variables in sql query - by stepgr - 06-26-2021, 02:17 AM
RE: Named variables in sql query - by InsiteFX - 06-26-2021, 05:41 AM
RE: Named variables in sql query - by stepgr - 06-29-2021, 06:42 AM
RE: Named variables in sql query - by includebeer - 06-29-2021, 05:41 PM
RE: Named variables in sql query - by php_rocs - 06-30-2021, 06:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB