CodeIgniter Forums
Avoid foreach() with Active Record? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Avoid foreach() with Active Record? (/thread-2800.html)



Avoid foreach() with Active Record? - El Forum - 08-24-2007

[eluser]stevefink[/eluser]
Hi all,

Is there any possibility for avoiding a foreach() construct when using Active Record type queries? For instance, I'm trying to receive just a single row/value from a table which can simply be assigned to a scaler, so using a foreach construct to get the results seems a bit overkill.

Thanks .... as usual. :-)

- sf


Avoid foreach() with Active Record? - El Forum - 08-24-2007

[eluser]Michael Wales[/eluser]
Code:
$query = $this->db->getwhere('users',  array('id'=>$id), 1, 0);
$row = $query->row()
echo $row->username;



Avoid foreach() with Active Record? - El Forum - 08-24-2007

[eluser]stevefink[/eluser]
Mike,

You're fast!

Thanks as always. :-)


Avoid foreach() with Active Record? - El Forum - 08-24-2007

[eluser]Michael Wales[/eluser]
heh - I just so happened to hop into the forums for the first time today and saw this post.

Bet you thought I just sit here refreshing all day, huh?

Note: That usually is the case, I was just really busy at work today and finally got a break.


Avoid foreach() with Active Record? - El Forum - 08-24-2007

[eluser]stevefink[/eluser]
I don't blame you for wanting to check out the forums often. The community here is wonderful and a pleasure to be around. Not to mention a kick ass framework that's making my life a lot easier than it normally would. I hope with experience and time I can help as much as you do. :-)