Active record WHERE clause not working? - 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: Active record WHERE clause not working? (/showthread.php?tid=39336) |
Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]xarazar[/eluser] Hi guys, I'm pretty sure I'm doing something incredibly daft here but after having spent a few hours I still can't find an answer. I just started with CI2 and the first thing that stopped me and my drags was something I completely didn't expect: I can't force $this->db->where() to work. The function is laughably simple: Code: function get_page($url = 'home'){ So... a unique url is passed on and I expect to receive only one result. Nope. The function works as if there was no WHERE clause at all! The commented line is the one I use right now to actually get the expected result. So what am I missing? Anybody experienced that? Many thanks. Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]InsiteFX[/eluser] Code: function get_page($url = 'home') InsiteFX Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]guidorossi[/eluser] You say that you're getting all the rows in the content table and only one should matches the WHERE clause? Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]xarazar[/eluser] @guidorossi Correct. Unbelievable but correct... Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]xarazar[/eluser] @InsiteFX Thanks buddy. But I want to make sure that there is only one record with the queried url hence the usage of $q->num_rows() == 1. I want the function to return false if there is more than one record with the same url. Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]guidorossi[/eluser] try enabling the profiler with Code: $this->output->enable_profiler(TRUE); at the beginning of the function where you call get_page to see if the query is correct. Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]xarazar[/eluser] It's getting interesting... The profiler tells me that no queries were run... But the whole page works fine when I use the manual query rather than Active Records. Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]InsiteFX[/eluser] Code: function get_page($url = 'home') InsiteFX Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]guidorossi[/eluser] well, trat's weird... I'm having the same code like: Code: function get_page($url = 'home'){ and on the profiler I get: Quote:DATABASE: citest QUERIES: 1 It seems to be all right... Active record WHERE clause not working? - El Forum - 03-08-2011 [eluser]xarazar[/eluser] Very weird indeed... I used a very specific routing solution $route['^(?!admin)\S*'] = "site/index/$1"; But I can't imagine what would this had to do with the WHERE clause not working... Perhaps it affects the profiler? Apart from that everything is just a fresh CI setup... |