CodeIgniter Forums
Fatal error: Call to undefined method CI_DB_mysql_driver::result() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Fatal error: Call to undefined method CI_DB_mysql_driver::result() (/showthread.php?tid=4880)



Fatal error: Call to undefined method CI_DB_mysql_driver::result() - El Forum - 12-21-2007

[eluser]ferno[/eluser]
hi guys, i'm getting the error:
Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::result() in /var/www/system/application/models/song_model.php on line 25
when I try to run a simple little function in one of my model classes that returns a random row

Code:
function get_random_entry()
{
    // SELECT column FROM table ORDER BY RAND() LIMIT 1            
    $query = $this->db->select('artist,title,location')->from('songs')->orderby(RAND())->limit(1);
    foreach ($query->result() as $row) // <- LINE 25
    {
        echo $row->artist;
        echo $row->title;
        echo $row->location;
    }
}

any ideas??


Fatal error: Call to undefined method CI_DB_mysql_driver::result() - El Forum - 12-21-2007

[eluser]RIVO10[/eluser]
maybe...
Code:
$query = $this->db->select('artist,title,location')->from('songs')->orderby('RAND()')->limit(1);



Fatal error: Call to undefined method CI_DB_mysql_driver::result() - El Forum - 12-21-2007

[eluser]ferno[/eluser]
nope, i tried using 'RAND()' and RAND()

EDIT: I found the solution, the correct code is:

Code:
$this->db->select('artist,title,location')->from('songs')->orderby('RAND()')->limit(1);

            $query = $this->db->get(); // the magic line :D

            foreach ($query->result() as $row)
        {
            echo $row->artist;
            echo $row->title;
            echo $row->location;
        }



Fatal error: Call to undefined method CI_DB_mysql_driver::result() - El Forum - 09-16-2010

[eluser]alive[/eluser]
Goodness. I just did the same things. Long live old posts!