Welcome Guest, Not a member yet? Register   Sign In
Active Record error with order_by random
#1

[eluser]fatdog[/eluser]
I'm getting this error.
Quote:Unknown column ' RAND() LIMIT 1' in 'order clause'
SELECT * FROM (`camp`) WHERE `secc` = 7 ORDER BY ` RAND() LIMIT 1

Code:
$this->db->order_by("id","random");
$this->db->where('secc',7);
$this->db->limit(1);
$query = $this->db->get('camp');

Am I doing something wrong?

I'm using version 1.7.0
#2

[eluser]jdfwarrior[/eluser]
What is the extra tick mark between order by and rand()?
To me... your syntax looks correct.
I just tried a similar query with something I have and it worked. I'm using 1.7.0 on that project too I believe. It may be 1.7.1 though, I don't remember.

Code:
$groups = $this->db->order_by("menugrouporder", "asc")->get("menugroups");

This was the code I used..
#3

[eluser]fatdog[/eluser]
[quote author="jdfwarrior" date="1234826985"]What is the extra tick mark between order by and rand()?[/quote]

I don't know, that's the error I get. Either I'm doing something wrong, or there is a bug with "random", because if I try "asc" or "desc" instead of "random" the script works.
#4

[eluser]jdfwarrior[/eluser]
I accidentally posted the code after I had changed it again. I used "random" and it still worked fine. As I said I dont remember which version I'm using. Maybe try upgrading to 1.7.1. Its just replacing contents of a few folders.
#5

[eluser]pistolPete[/eluser]
[quote author="jdfwarrior" date="1234827788"]Maybe try upgrading to 1.7.1.[/quote]
Definitely, just have a look at the changelog:
Quote:Fixed a bug when doing 'random' on order_by() (#5706).
#6

[eluser]jdfwarrior[/eluser]
Ha nice.




Theme © iAndrew 2016 - Forum software by © MyBB