MySQL select--Need Help |
I am not very good at mysql.
I have this query working: SELECT player1 Player, round(sum(masterpoints),2) Total FROM scores2014 GROUP BY Player UNION SELECT player2 Player, round(sum(masterpoints),2) Total FROM scores2014 GROUP BY Player order by Total DESC When I attempt to get it working in Codeigniter I use: $this->db->select( "player1 Player, round(sum(masterpoints),2) Total FROM scores2014 GROUP BY Player UNION SELECT player2 Player, round(sum(masterpoints),2) Total FROM scores2014 GROUP BY Player order by Total DESC"); and get an error message saying the mysql is wrong. Anyone see the error of may ways? Thanks, Bill
Since you're using UNION, you would most likely want to use $this->db->query() instead of $this->db->select().
When using $this->db->select(), you would normally only pass the SELECT portion of your SQL query into the select() method, then you would use other methods (e.g. from(), group_by(), join()) to handle the rest of your SQL. Since CI doesn't include a union() method in the database library, you would either have to rewrite the SQL as a join or pass the whole SQL statement to $this->db->query(). (01-05-2015, 01:42 PM)mwhitney Wrote: Since you're using UNION, you would most likely want to use $this->db->query() instead of $this->db->select(). Thanks, I rewrote the code to us $this-db-select, but it still does not work. The code now is: Code: $query = $this->db->query( Any other suggestions to get the mysql working in Codeigniter? Bill
"It does not work" is not a description of the problem! What is the error message you get?
(01-05-2015, 09:55 PM)bhogsett Wrote:(01-05-2015, 08:35 PM)includebeer Wrote: "It does not work" is not a description of the problem! What is the error message you get? Cool! |
Welcome Guest, Not a member yet? Register Sign In |