Codeigniter Order by random records from mysql database example

Codeigniter If you are finding way to how to get random records from mysql table in codeigniter project then you are a right place. You can easily get random rows using codeigniter query builder order_by. here you will see the example of getting random result using order_by. okay to thanks to my blog follow and like this is new feature like this helpful and another blog is very soon with share with you..

In order_by(), we have to pass two argument parameter, one is a column name and another is a ‘RANDOM’ then Codeigniter query builder class will return random value every time from mysql database table. So just check bellow example for codeigniter:

Example 1:

$this->db->order_by('id','RANDOM');
  
$data = $this->db->get("items");

Example 2:

$this->db->order_by(42,'RANDOM');

$data = $this->db->get("items");

You can check now.

I hope you found your solution…

Leave a Comment