Codeigniter 3 - Order by random records from mysql database example

July 19, 2018 | Category : MySQL Codeigniter PHP

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 in codeigniter 3.

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:

Example 1:


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

Example 2:


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

You can check now.

I hope you found your solution...