DB related code - make it simple and fast |
[eluser]Yash[/eluser]
Code: //GetCats Code: $cats=self::GetCats(); Please make it fast or simple code
[eluser]parrots[/eluser]
Hopefully this will simplify things: Code: $query = $this->db->get('categories'); Code: $cats=self::GetCats(); In getCats result_array() returns an array of rows where each row is an array instead of an object ($row['column'] vs $row->column). In your other code you don't need to use that second nested for loop. You can make use of the in_array to see if one object is in another array. You can also use foreach to loop through arrays without having to keep track of the index. That's a personal preference, either way will work, I just find it easier to read and it saves you a counter variable.
[eluser]Yash[/eluser]
that was awesome!! dude that is really good job. Thank you so much
[eluser]xwero[/eluser]
Wouldn't it be simpler to do Code: $cats = '';
[eluser]Yash[/eluser]
Strange Error ... Fatal error: Call to a member function result() on a non-object in near problem is in this section foreach($query->result() as $row) { $temp[] = $row->Cat; }
[eluser]Armchair Samurai[/eluser]
xwero's code is missing the actual query: Code: $this->db->select('Cat')->from('categories')->where_in($posts['CatID']);
[eluser]Yash[/eluser]
This time works perfectly... and this code saves a lot time and much better approach. Thank you xwero and Armchair Samurai |
Welcome Guest, Not a member yet? Register Sign In |