How do I do "while fetching" in CodeIgniter?

What is the equivalent code that will run the code, get and write all the variables ...

Here's what I would normally do like this:

$get = mysql_query("SELECT * FROM aTable");

while($row = mysql_fetch_assoc) {
echo $row['someContent'];
}

      

How can I do this in codeigniter?

+3


source to share


1 answer


After executing the query, use ->query()

either the "active record" class ->get()

using the method result_array

.

$query = $this->db->query("SELECT * FROM aTable");

foreach($query->result_array() as $row){
    echo $row['someContent'];
}

      



Docs: http://ellislab.com/codeigniter/user-guide/database/results.html

+8


source







All Articles