ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Fatal error: Call to undefined method CI_DB_mysql_driver::result()

December 21, 2007 3:54am

Subscribe [1]
  • #1 / Dec 21, 2007 3:54am

    ferno

    11 posts

    hi guys, i’m getting the error:

    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

    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??

  • #2 / Dec 21, 2007 7:41am

    RIVO10

    5 posts

    maybe…

    $query = $this->db->select('artist,title,location')->from('songs')->orderby('RAND()')->limit(1);
  • #3 / Dec 21, 2007 4:23pm

    ferno

    11 posts

    nope, i tried using ‘RAND()’ and RAND()

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

    $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;
            }
  • #4 / Sep 16, 2010 8:21pm

    alive

    3 posts

    Goodness. I just did the same things. Long live old posts!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases