tags:

views:

103

answers:

1

How do I select multiple rows from SQL?

ie. $results->row(1,2,3,4,5,10)

+1  A: 

Are you using ActiveRecord? If so, you can use the where_in() method when making your query. It's not something you do after the query is finished, as you seem to be doing in your example.

$this->db->where_in('id', array(1,2,3,4,5,10));
$query = $this->db->get('myTable');
// This produces the query SELECT * FROM `myTable` WHERE `id` IN (1,2,3,4,5,10)

See the this CodeIgniter docs section for more info on SELECT statement support.

Marc W
I need to run some more commands later...So if I wanted to say $query->row()... is there a way to select rows this way--if the query selects all rows first?
Kevin Brown
No. That's not how it works. `$query->row()` is only for getting each of the rows already selected by the query. You can't filter any further without doing manual filtering (which is silly). You can make more queries later if you want. Calling `get()` ends the transaction so you can just start over and calling more methods on `$this->db` without doing anything special.
Marc W
Whao! Good to know!
Kevin Brown