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:
$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...
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?