Welcome Guest, Not a member yet? Register   Sign In
cant get a random mysql selection going :(
#5

[eluser]ommy[/eluser]
There was a reason indeed. I was checking the your reply from a mobile device and didnt have the files on that device.
Here's the actual copy-pasted code.

Code:
$this->db->order_by('id','random');
$this->db->limit(1);
$row = $this->db->get_where('gallery',array('active' => 1, 'public'=> 1))->row();
I messed around with situations a bit more and it seems that the following ways do work:
Code:
$random_row = mysql_fetch_row(mysql_query("select * from gallery order by rand() limit 1"));
$random_row = $this->db->query('select * from gallery order by rand() limit 1')->row();
i thought it was solved with this, but turned out to ignore the rand():
Code:
$this->db->order_by('id','rand()');
$random_row = $this->db->get_where('gallery',array('active' => 1, 'public'=> 1))->row();
and finally i just tried regular old mysql, which worked perfectly:
Code:
$row = $this->db->query('select * from gallery where active=1 and public=1 order by rand() limit 1')->row();
could the backtick you're talking about be a typo in the constant for random?
I'm probably on the wrong track with this. Just trying to figure out what it is i missed.
Doesn't seem like too hard of an operation.

Thanks for the reply. I'll remind myself never to be sure about syntax Smile


Messages In This Thread
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 08:00 AM
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 08:15 AM
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 09:23 AM
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 12:01 PM
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 07:01 PM
cant get a random mysql selection going :( - by El Forum - 09-12-2009, 08:07 PM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 07:52 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 08:38 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 08:50 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 09:04 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 09:07 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 09:10 AM
cant get a random mysql selection going :( - by El Forum - 09-13-2009, 09:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB