CodeIgniter Forums
Throwing multiple rows, selected from the DB in one variable. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Throwing multiple rows, selected from the DB in one variable. (/showthread.php?tid=51293)



Throwing multiple rows, selected from the DB in one variable. - El Forum - 04-27-2012

[eluser]Milo[/eluser]
I am new to codeIgniter, and for some reason I cannot wrap my head around this problem. I want to make a variable that I can echo within the view, and pull multiple rows from a table that I have from one column.

so for example:

My table:

user_id file_id firstname

2 1 john smith
2 2 john smith
2 3 john smith
2 4 john smith
2 5 john smith


how can I throw the file_id's into one variable and call all of them from my table, and then put a limit on how many I want to pull. Then use the variable to echo them in the view.

Thank you guys for all your help in advance!


Throwing multiple rows, selected from the DB in one variable. - El Forum - 04-28-2012

[eluser]Stefan Hueg[/eluser]
Code:
$result = $this->db->select('*')
->from('my_table')
->where_in('file_id', array(1,2,3,4,5))
->limit(...)
->get();

Is that the solution you were asking for?