How to get random records in MySQL using CodeIgniter?

by bailey_conroy , in category: Technology , 3 years ago

How to get random records in MySQL using CodeIgniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by trycia.jones , 3 years ago

order_by function is used to order the records from a table in CodeIgniter.

1
2
3
4
5
// Getting random rows from database in CodeIgniter
$this->db->select('*');
$this->db->from('table_name');
$this->db->order_by("column_name", "random");
$result = $this->db->get()->result();