-
PARADISE Newbie

-
Posts: 9
Threads: 3
Joined: Jan 2015
Reputation:
0
Hello, I'm trying to convert the query below into CI's Active Record form, but I get an error :
a.alliance_id could not be bound.
Here is the sql query (when i run it directly to SQL Server works fine)
PHP Code: SELECT * , a.pledge_id, a.ruler_id AS Expr2, a.name AS pledge_name, a.alliance_id AS Expr4, a.challenge_time AS Expr5, a.root_name_value AS Expr6, a.now_war_id AS Expr7, a.oust_time AS Expr8, a.skill_level AS Expr9, a.castle_id AS Expr10, a.agit_id AS Expr11, a.rank AS Expr12, name_value AS Expr13, a.status AS Expr14, a.private_flag AS Expr15, a.crest_id AS pledge_crest_id, a.is_guilty AS Expr17, a.dismiss_reserved_time AS Expr18, a.alliance_withdraw_time AS Expr19, a.alliance_dismiss_time AS Expr20, a.alliance_ousted_time AS Expr21, b.char_name, c.name as ally_name, c.crest_id as ally_crest_id from pledge as a left join user_data as b on a.ruler_id=b.char_id left join alliance as c on a.alliance_id=c.id order by a.skill_level desc
Here is where I got so far. (Maybe I have some syntax error's?)
Thank you in advance!!
PHP Code: ->select("* , a.pledge_id, a.ruler_id AS 'Expr2', a.name AS 'pledge_name', a.alliance_id AS 'Expr4', a.challenge_time AS 'Expr5', a.root_name_value AS 'Expr6', a.now_war_id AS 'Expr7', a.oust_time AS 'Expr8', a.skill_level AS 'Expr9', a.castle_id AS 'Expr10', a.agit_id AS 'Expr11', a.rank AS 'Expr12', name_value AS 'Expr13', a.status AS 'Expr14', a.private_flag AS 'Expr15', a.crest_id AS 'pledge_crest_id', a.is_guilty AS 'Expr17', a.dismiss_reserved_time AS 'Expr18', a.alliance_withdraw_time AS 'Expr19', a.alliance_dismiss_time AS 'Expr20', a.alliance_ousted_time AS 'Expr21', b.char_name, c.name AS 'ally_name', c.crest_id AS 'ally_crest_id'") ->join('user_data as b', 'a.ruler_id = b.char_id', 'left outer') ->join('Alliance as c', 'a.alliance_id = c.id', 'left outer') ->order_by('a.skill_level', 'DESC') ->get('Pledge as a');
-
php_rocs Administrator
      
-
Posts: 1,416
Threads: 104
Joined: Jun 2016
Reputation:
73
03-11-2019, 01:15 PM
(This post was last modified: 03-11-2019, 01:16 PM by php_rocs.)
@ PARADISE,
I think your missing some pieces of the query builder...
->from('Pledge as a')
->join('user_data as b', 'a.ruler_id = b.char_id', 'left outer')
->join('Alliance as c', 'a.alliance_id = c.id', 'left outer')
->order_by('a.skill_level', 'DESC')
->get();
-
php_rocs Administrator
      
-
Posts: 1,416
Threads: 104
Joined: Jun 2016
Reputation:
73
03-11-2019, 01:22 PM
(This post was last modified: 03-11-2019, 01:26 PM by php_rocs.)
@ PARADISE,
Or as I like it...using query bindings( https://www.codeigniter.com/userguide3/d...y-bindings )...
PHP Code: $qry ="SELECT * , a.pledge_id, a.ruler_id AS Expr2, a.name AS pledge_name, a.alliance_id AS Expr4, a.challenge_time AS Expr5, a.root_name_value AS Expr6, a.now_war_id AS Expr7, a.oust_time AS Expr8, a.skill_level AS Expr9, a.castle_id AS Expr10, a.agit_id AS Expr11, a.rank AS Expr12, name_value AS Expr13, a.status AS Expr14, a.private_flag AS Expr15, a.crest_id AS pledge_crest_id, a.is_guilty AS Expr17, a.dismiss_reserved_time AS Expr18, a.alliance_withdraw_time AS Expr19, a.alliance_dismiss_time AS Expr20, a.alliance_ousted_time AS Expr21, b.char_name, c.name as ally_name, c.crest_id as ally_crest_id from pledge as a left join user_data as b on a.ruler_id=b.char_id left join alliance as c on a.alliance_id=c.id order by a.skill_level desc";
$this->db->query($qry);
-
PARADISE Newbie

-
Posts: 9
Threads: 3
Joined: Jan 2015
Reputation:
0
Will try to edit like you mentioned and see the results! Thanks!
-
PARADISE Newbie

-
Posts: 9
Threads: 3
Joined: Jan 2015
Reputation:
0
(03-11-2019, 01:15 PM)php_rocs Wrote: @PARADISE,
I think your missing some pieces of the query builder...
->from('Pledge as a')
->join('user_data as b', 'a.ruler_id = b.char_id', 'left outer')
->join('Alliance as c', 'a.alliance_id = c.id', 'left outer')
->order_by('a.skill_level', 'DESC')
->get();
You were right! It worked that way!
-
php_rocs Administrator
      
-
Posts: 1,416
Threads: 104
Joined: Jun 2016
Reputation:
73
|