Random Query |
[eluser]Philo01[/eluser]
Hi there! I'm trying to pull random data from a table, and found the following "solution": http://www.derekallard.com/blog/post/ord...deigniter/ Code: $this->db->select('name'); Now when I apply this method on my application, I get the following error: Quote:A PHP Error was encountered My model returns the array to my controller: Code: $this->db->where('activated', '1'); Next, my Controller sends the array to a view: Code: foreach($ads as $a){ When I use this code without the shuffle part it works perfect, only it doesn't select randomly. When I use the shuffle solution, I get that error. Anyone who can help me out ![]() Kind regards, Philo
[eluser]CtheB[/eluser]
Sorry i don't use active record in codeigniter so i can't help you. It is much easier to do it like this: $query = $this->db->query("SELECT * FROM orders where activated = 1 AND expired = 0 ORDER BY rand() "); return $query->result_array();
[eluser]Philo01[/eluser]
[quote author="CtheB" date="1260490524"]Sorry i don't use active record in codeigniter so i can't help you. It is much easier to do it like this: $query = $this->db->query("SELECT * FROM orders where activated = 1 AND expired = 0 ORDER BY rand() "); return $query->result_array();[/quote] Thanks mate! ![]()
[eluser]jedd[/eluser]
I believe (but have not tested or confirmed) that it is preferable, for performance reasons, to query the database on the number of rows in the table, use a local PHP random function against that figure, and then extract that specific record from the database.
[eluser]WhitecastlePT[/eluser]
Hello, here's an example with active records: Works like a charm ![]() Code: function getAllFotos() |
Welcome Guest, Not a member yet? Register Sign In |