Getting single DB results |
[eluser]rvent[/eluser]
Hello, I am having this little problem that i cant seem to find a solution to. I am executing a query to my DB to get a single record once i get it it is used by another function to get the list of records who belong to that value. EX: I have a workOrder 12345 and workOrder 12345 has many messages all of which have an association to their respective workOrder. Here is my model function: Code: function getWOid($woID) And here is my test controller function: Code: function testDB() ANd certainly this is a no go since i get error about object properties: Code: $woID = $this->SmtJob->getWOid($wId); the docs say that using "query->" i would need to use the http://ellislab.com/codeigniter/user-gui...sults.html but i feel like using a whole block to get 1 result its a little too much.. Is there another way to get a single result other than: Code: $query = $this->db->query("YOUR QUERY"); Thanks..
[eluser]rvent[/eluser]
Well thats what i had tried before Code: $woID = $this->SmtJob->getWOid($wId); and it didnt work.. Must i use a "foreach"..? I was trying to jsut assign it to variables instead of using a foreach block.. Thanks...
[eluser]Michael Wales[/eluser]
Code: function testDB() { Code: function getWOid($woID) {
[eluser]tobben[/eluser]
$this->db->where('id', 1); $query = $this->db->get('cms_customers'); $row = $query->row(); echo $row->title;
[eluser]Tom Glover[/eluser]
Even to get a single row i found that I had to place it in a foreach.
[eluser]Michael Wales[/eluser]
Quote:Even to get a single row i found that I had to place it in a foreach. You shouldn't have to at all. The one thing to watch out for: the row() method returns an object. Most people pass an array to their Views. Let's use this horrible example below - make sure to read the comments. Code: function test() { $one_post will be an object, so you will have to reference it's values like: Code: echo $one_post->title; $two_posts will be an object, so: Code: foreach ($two_posts as $post) { $three_posts will be an array, so: Code: foreach ($three_posts as $post) {
[eluser]rvent[/eluser]
[quote author="Michael Wales" date="1211921295"] Code: function testDB() { Code: function getWOid($woID) { I dont see how i couldnt get it to work before, but now it works... Case of a mondays on tuesday..? maybe... Thanks! |
Welcome Guest, Not a member yet? Register Sign In |