faster,better way to get stuff from db + add/edit theory |
[eluser]xpix[/eluser]
How would you improve the following: (I am trying to get the status field from jobs table) Code: //get job status Thx
[eluser]sophistry[/eluser]
what you have is perfectly fine. but, if you only want one row the best thing to do is to use LIMIT either in Active Record method or as a parameter sent to the get method. then to get just one row from the $query you use $query->row(). this cleans up the code a little. Code: $this->db->select('status');
[eluser]Yash[/eluser]
Code: $this->db->select('status');
[eluser]xpix[/eluser]
another thing how do you manage add and edit controllers into one Eg Code: function addUser(){ Would you use a function user($action, $id) where $action is "add" or "edit"? Is there a better way?
[eluser]sophistry[/eluser]
yes, "don't repeat yourself" (sometimes people make this an acronym DRY). since add and edit do the same thing to the same table try to cut down on extra code to save yourself typing and debugging. seems like you might be ready to check out IgnitedRecord. http://ellislab.com/forums/viewthread/78305/
[eluser]xpix[/eluser]
Thx, I will check that out Meanwhile is there a better way for Code: $myquery = "select jobs.id, jobs.title, jobs.company, jobs.address,"; (not an expert in SQL) Unfortunately could not figure how to do it with joins
[eluser]codex[/eluser]
[quote author="xpix" date="1217553874"]Thx, I will check that out Meanwhile is there a better way for Code: $myquery = "select jobs.id, jobs.title, jobs.company, jobs.address,"; (not an expert in SQL) Unfortunately could not figure how to do it with joins[/quote] I don't have the solution, but was just wondering: is the '?' in the query valid?
[eluser]Hannes Nevalainen[/eluser]
The '?' will get replaced by the data in the second param to $this->db->query();
[eluser]codex[/eluser]
[quote author="Hannes Nevalainen" date="1217554373"]The '?' will get replaced by the data in the second param to $this->db->query();[/quote] Interesting. Never heard of this function. |
Welcome Guest, Not a member yet? Register Sign In |