cant get a random mysql selection going :( - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: cant get a random mysql selection going :( (/showthread.php?tid=22524) Pages:
1
2
|
cant get a random mysql selection going :( - El Forum - 09-12-2009 [eluser]ommy[/eluser] Hi there, I ran into a problem trying to use the order_by:random method. It's probably something stupid i'm not seeing on this goofy saturday. But a lot of googling and reading up on the distinct, mysql, php etc. didnt help yet. I'm taking the leap and asking here. There's bound to be someone here kind enough to point out my ignorance ps: This is the error codeigniter/mysql is spitting out: Code: A Database Error Occurred Thanks in advance for any help! Tommy cant get a random mysql selection going :( - El Forum - 09-12-2009 [eluser]jedd[/eluser] Code: Unknown column ' RAND() LIMIT 1' in 'order clause' Well, yes - it's the backtick before RAND What's your code for generating this query? cant get a random mysql selection going :( - El Forum - 09-12-2009 [eluser]ommy[/eluser] forgive me for the pseudo code. but i doubt its a syntax error. the sequence of the db actions is exact though. thanks for yr reply Code: db orderby id random cant get a random mysql selection going :( - El Forum - 09-12-2009 [eluser]jedd[/eluser] [quote author="ommy" date="1252787014"] forgive me for the pseudo code. [/quote] Is there a reason you can't cut-n-paste the actual code you're using? Quote:but i doubt its a syntax error. If only your doubt was sufficient to resolve the problem. The error message you're showing above is fairly explicit - it says it can't understand the column 'RAND ...' , and there's a backtick clearly visible. The latter would induce the former error. Quote:the sequence of the db actions is exact though. It's not a sequencing problem. cant get a random mysql selection going :( - El Forum - 09-12-2009 [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'); Code: $random_row = mysql_fetch_row(mysql_query("select * from gallery order by rand() limit 1")); Code: $this->db->order_by('id','rand()'); Code: $row = $this->db->query('select * from gallery where active=1 and public=1 order by rand() limit 1')->row(); 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 cant get a random mysql selection going :( - El Forum - 09-12-2009 [eluser]jedd[/eluser] You don't keep a full cvs of your source on your blackberry?!?! Odd, the first set you show there - that should work. random's supported on mysql, and you're right about this not being a complex construct. What happens if you relocate your limit to the get_where (third param) - what's the actual query produced then? If that works, then it looks like a bug. I don't use AR calls, so I'm not the best person to be answering this (actually that's why I wanted to see your code, in case you were using a self-constructed query). cant get a random mysql selection going :( - El Forum - 09-13-2009 [eluser]ommy[/eluser] same error gets thrown. I've tried to use the profiler to get to see the actual query. But it seems the error cancels out the profiler being printed. So i'll guess i'll have to take the error's word for it when it comes to the actual built query I'll check out if i can find the method causing this, maybe it's just a monday-morning typo cant get a random mysql selection going :( - El Forum - 09-13-2009 [eluser]ommy[/eluser] been playing around with the mysql driver and the activerecord class and the backtick indeed looks like a tiny bug that shows up because no column is specified. Hope my playing around leads to something constructive cant get a random mysql selection going :( - El Forum - 09-13-2009 [eluser]ommy[/eluser] the ar_orderby for compile_select at 1545 of the active record class is the culprit. I don't think it's the cause of the backtick though. cant get a random mysql selection going :( - El Forum - 09-13-2009 [eluser]ommy[/eluser] retarded solution number one (DB_active_rec.php – line 1544): Code: //$sql .= implode(', ', $this->ar_orderby); // original line Code: $this->db->order_by('id','random'); If anyone can find the true cause of this odd backtick, yr welcome to share Thanks a bunch already |