Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to undefined method CI_DB_mysql_driver::result()
#1

[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??
#2

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

[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;
        }
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB