Problem with join |
[eluser]Sein Kraft[/eluser]
This my code but it down't work properly because the user.id should be 24 and is returning the rank.id as user.id. Code: $query_users = $this->db Quote:Array Help please!
[eluser]Jondolar[/eluser]
What do your tables look like? Do you have multiple tables with field names of "id"?
[eluser]John_Betong[/eluser]
Try: Code: echo $this->db->last_query();
[eluser]Sein Kraft[/eluser]
LastQuery: Code: FROM (`users`) JOIN `roles` ON `roles`.`id` = `users`.`role` JOIN `ranks` ON `ranks`.`id` = `users`.`rank` LIMIT 1 Tables: Code: CREATE TABLE IF NOT EXISTS ranks (
[eluser]John_Betong[/eluser]
Try changing your join to something like this : Code: ->join('roles as id_roles', 'id_roles.id = users.role') edit: forgot to change the table name
[eluser]Sein Kraft[/eluser]
error: Quote:Unknown column 'roles.id' in 'on clause' The query was replacing users.id with roles.id and for the last with rank.id. Finally i've change the name of the column of roles.id to roles.role_id in the sql table. But its an ugly solution.
[eluser]überfuzz[/eluser]
[quote author="Sein Kraft" date="1260045300"]error: Quote:Unknown column 'roles.id' in 'on clause'[/quote] Well John Betong assumed that you actually had a table called roles with a column called id. Could you show us your tables? Not type how to go about creating them.
[eluser]Unknown[/eluser]
If you want to join multiple tables with the same column name, you must change alias column in select statement. Example: $this->db->select('users.*, roles.id as r_id'); You will receive the result with id of users table and r_id of roles table If you don't use alias for the same column in select statement, the result with return only id of roles table
[eluser]John_Betong[/eluser]
Using PhpMyAdmin I created your tables and also this query. The query runs without any errors. You did not copy the code that I sent correctly, the roles and ranks table name aliasii/aliases table names were incorrect. Code: SELECT * FROM users edit: spelling |
Welcome Guest, Not a member yet? Register Sign In |