Hello, Im new to kohana 3 here, and my understanding of it is very limited.
The problem is instead of displaying the first row, what code should I use when I'll try to get a random row from a certain table?
BTW: I'm using the ORM module.
Thanks
Hello, Im new to kohana 3 here, and my understanding of it is very limited.
The problem is instead of displaying the first row, what code should I use when I'll try to get a random row from a certain table?
BTW: I'm using the ORM module.
Thanks
You can issue the query directly, if you are using MySQL:
SELECT * FROM table LIMIT 1 ORDER BY RAND();
Or with Kohona Query Builder:
$this->db->from('table')->select('*')->limit(1)->orderby(null, 'RAND()')->get();
You can use this (if using MySQL):
ORM::factory('some_model')->order_by(DB::expr('RAND()'))->find();