How to get random records in MySQL using CodeIgniter?

by bailey_conroy , in category: Technology , 4 years ago

How to get random records in MySQL using CodeIgniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by trycia.jones , 4 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(); 


Related Threads:

How to get last inserted id in CodeIgniter?
How to set or get config variables in Codeigniter?
How to Improve Mysql Performance for Large Databases?
What Are the Key Differences Between Postgresql and Mysql?
What Are the Key Features That Make Codeigniter Ideal for Rapid Php Application Development?
How to Integrate a Third-party Api with Ruby on Rails?