Welcome Guest, Not a member yet? Register   Sign In
Best way to get a random element in MySQL Database
#6

[eluser]xwero[/eluser]
From that discussion i think you can this rule of thumb
Quote:i think we should do it case by case, if your database is small, mustapha code can be implemented. otherwise use PHP random code.
They are speaking about tables with more than a million rows.

I think the only way to do this with AR would be
Code:
$query = $this->db->where('picture_ID >= (SELECT FLOOR(MAX(picture_ID) * RAND()) FROM gallery )')->orderby('picture_ID')->limit(4)->get('gallery');
You are working with a subquery and that isn't introduced yet in the AR library.


Messages In This Thread
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 08:30 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:01 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:04 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:22 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:25 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:43 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 09:47 AM
Best way to get a random element in MySQL Database - by El Forum - 05-09-2008, 10:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB