set sql variable before main query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: set sql variable before main query (/showthread.php?tid=72766) |
set sql variable before main query - ash-f - 02-08-2019 Is it possible to set sql variable before other queries?(not $this->db->query()) I'd like to do something like this. PHP Code: $this->db->query("SET @min_id := (SELECT min_id FROM shop_parameter)"); RE: set sql variable before main query - php_rocs - 02-08-2019 @ash-f, Yes, it is possible to set sql variable before other queries. The catch is...not the way you have it in your example. There are a couple of ways that you could do it but you would have to use $this->db->query(). With one of those ways, you could actually do it in one query but again it is using the $this->db-query(); RE: set sql variable before main query - InsiteFX - 02-09-2019 PHP Code: $this->db->where('(item_id > @min_id',NULL,FALSE); Are you missing a parentheses / bracket here? RE: set sql variable before main query - ash-f - 02-12-2019 (02-09-2019, 05:16 AM)InsiteFX Wrote: That is a typo created when I copy&pasted from the original code. In the original code, I used (item_id > @min_id AND item_id < @max_id) RE: set sql variable before main query - ash-f - 02-12-2019 (02-08-2019, 05:46 PM)php_rocs Wrote: @ash-f, Thanks. I saw something similar and they are using transaction with multiple $this->db-query(). So is that the standard way? RE: set sql variable before main query - ash-f - 02-12-2019 Ok, I've used two successive $this->db->query() Code: $randomitem=array(); RE: set sql variable before main query - php_rocs - 02-13-2019 @ash-f, Documentation for future reference (of query results)... https://codeigniter.com/user_guide/database/results.html#generating-query-results RE: set sql variable before main query - ash-f - 02-14-2019 (02-13-2019, 09:27 PM)php_rocs Wrote: @ash-f, Thank you |