CodeIgniter Forums
Queery Model Action - 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: Queery Model Action (/showthread.php?tid=34498)



Queery Model Action - El Forum - 10-01-2010

[eluser]seanloving[/eluser]
I can't figure out why my query is returning the
Code:
CI_DB_mysql_driver Object ( ...
instead of expected query results. WTF? Anybody know the obvious? Thanks. -SL


Queery Model Action - El Forum - 10-01-2010

[eluser]techgnome[/eluser]
What it returns is a query object... to get the results you need to use the ->result() call which will return the results themselves. http://ellislab.com/codeigniter/user-guide/database/results.html

-tg


Queery Model Action - El Forum - 10-01-2010

[eluser]CroNiX[/eluser]
Code:
$q = $this->db->select('name')->where('id', $id)->get('table');

$q will equal the result set here.  However, you can still run:
foreach($q->result() as $row)
{
    echo $row->name . '<br />';
}

$q = $this->db->select('name')->where('id', $id)->get('table')->result_array();   (or ->results()....or ->row()...or...read the docs for the possibilities :)  )

$q = the data in the result set, as an array
foreach($q as $row)
{
    echo $row['name'] . '<br />';
}
Its no different than straight php/mysql.