Welcome Guest, Not a member yet? Register   Sign In
Random Query
#1

[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');
$query = $this->db->get('table');
$shuffled_query = $query->result_array();
shuffle ($shuffled_query);

foreach ($shuffled_query as $row) {
    echo $row['name'] . '<br />';
}

Now when I apply this method on my application, I get the following error:

Quote:A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

My model returns the array to my controller:

Code:
$this->db->where('activated', '1');
$this->db->where('expired', '0');
$ads = $this->db->get('orders');
return shuffle($ads->result_array());

Next, my Controller sends the array to a view:

Code:
foreach($ads as $a){
      // code here
}

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 Smile ?

Kind regards,

Philo


Messages In This Thread
Random Query - by El Forum - 12-10-2009, 12:06 PM
Random Query - by El Forum - 12-10-2009, 12:15 PM
Random Query - by El Forum - 12-10-2009, 04:02 PM
Random Query - by El Forum - 12-10-2009, 04:40 PM
Random Query - by El Forum - 08-27-2012, 05:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB