Posted inphp / Codeigniter

sort query order by in codeigniter Examples

Today, We want to share with you sort query order by in codeigniter .In this post we will show you order by in ci, hear for multiple column orderby in codeigniter we will give you demo and example for implement.In this post, we will learn about orderby in codeigniter with an example.

sort query order by in codeigniter

There are the Following The simple About order by desc in codeigniter Full Information With Example and source code.

As I will cover this Post with live Working example to develop order_by in codeigniter, so the sort by alphabetical order in codeigniter is used for this example is following below.

sort query orderby in codeigniter
sort query orderby in codeigniter

order_by() Query in Codeigniter

The CI Based order from() function is used in the simple MySQL Database table ascending as well s descending order to sorting or arrange the all the Data result-set. The first parameter added the Database table column Like as a product_title by which you want to any order Like as a ASC or DESC. The second parameter allows you to set the result’s course. It’s ASC, DESC as well as RANDOM selection data.

MySQL Database Table Sort table data in ascending or descending order in Codeigniter

using DESC

orderby descending in codeigniter

$this->db->order_by('product_code', 'DESC');
// Stored Produces: ORDERBY `product_code` DESC

Using Passing Data with ASC

orderby asc in codeignitersimple We can also pass the arguments your own data string MySQL table in the 1st parameter

$this->db->order_by('product_code DESC, product_title ASC');
// Stored Produces: ORDERBY `product_code` DESC, `product_title` ASC

Using multiple function & fields

Or multiple method calls can be made if you required the one or more multiple fields.

$this->db->order_by('product_code', 'DESC');
$this->db->order_by('product_title', 'ASC');
// Stored Produces: ORDERBY `product_code` DESC, `product_title` ASC

Usiong RANDOM

If you select the RANDOM direction option.orderby random in codeigniter

$this->db->order_by('product_code', 'RANDOM');
// Stored Produces: ORDERBY RAND()

$this->db->order_by(50, 'RANDOM');
// Stored Produces: ORDERBY RAND(50)

CodeIgniter Order By Query Example

MySQL Table: Doctors

$this->db->select('*');
$this->db->from('table_Doctors');
$this->db->order_by('DoctorName');
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY DoctorName;

CodeIgniter Order By Asc:

$this->db->select('*');
$this->db->from('table_Doctors');
$this->db->order_by('hospital', 'asc');
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY hospital asc;

CodeIgniter Order By Desc:

$this->db->select('*');
$this->db->from('table_Doctors');
$this->db->order_by('hospital', 'desc');
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY hospital desc;

CodeIgniter Order By Two Columns:

$this->db->select('*');
$this->db->from('table_Doctors');
$this->db->order_by('Staff', 'desc');
$this->db->order_by('DoctorName', 'asc');
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY Staff desc, DoctorName asc;

Method Chaining in CodeIgniter:

$this->db->select('*')->from('table_Doctors')->order_by('Staff desc, DoctorName asc');
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY Staff desc, DoctorName asc;

CodeIgniter Order By Limit:

$this->db->select('*');
$this->db->from('table_Doctors');
$this->db->order_by('Staff', 'asc');
$this->db->limit(3, 1);
$query = $this->db->get();
return $query->result();

// Produces SQL
// SELECT * FROM table_Doctors ORDERBY Staff ASC LIMIT 1, 3;
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about limit in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype