[eluser]Unknown[/eluser]
I am building an application to teach myself Codeigniter. I would like some help converting a sql query into active record directives.
I have a query that I have got to work using the basic database methods in codeigniter. I would like to understand the active record structure and learn more about this, so i can use the active record structure (for learning and for code consistency)
I have a list of users in a table called UserList and there are 2 other tables that contain information relating to aspects of my application.
Ultimately what I would like is to get all the fields from the UserList and then extra columns on the end with the Category Name (from the CategoryList table) and the Time of the last user action (from the UserTimeLog table)
My solution is working at the moment (possible returning too much data,) but the tables are not going to be very big... probably less than 200 users and maybe 8 to 10 different categorites to choose from. The UserTimeLog could potentially have 1000's of records to search but that will be the only consideration as far as streamlining my query goes. I don't mind getting extra fields in the return array.
Code:
$sql="SELECT * FROM (UserList LEFT JOIN CategoryList ON UserList.Category = CategoryList.CategoryID) LEFT JOIN UserTimeLog ON UserList.LastAction = UserTimeLog.EventID";
$query = $this->db->query($sql);
return $query->result_array();
I have tried several methods of doing this with active record with no measure of success.
I deleted the code that I had written out of frustration and re-pasted the working function into my model to get my application working again. Any advice or help would be very much appreciated.