We do the ordering method for sorting the data then. In the first parameter we pass the column name and set the type in the second parameter. Codeigniter provided three type of order like as : ASC order for old records first, DESC order for new records first, RANDOM order show randomly records.
The oldest record in ASC order shows at first position.
public function order_data()
{
$query = $this->seller->table('users')
->orderBy('id','ASC')
->get();
echo "<pre>";
print_r($query->getResult());
}
The latest record in DESC order is the show at first position.
public function order_data()
{
$query = $this->seller->table('users')
->orderBy('id','DESC')
->get();
echo "<pre>";
print_r($query->getResult());
}
The record in RANDOM order shows in random positions.
public function order_data()
{
$query = $this->seller->table('users')
->orderBy('id','RANDOM')
->get();
echo "<pre>";
print_r($query->getResult());
}
If the records have to be hold to some limit, then we do the limit.
public function order_data()
{
$query = $this->seller->table('users')
->limit(3)
->get();
echo "<pre>";
print_r($query->getResult());
}
In limit we can set offset in second parameter.
public function order_data()
{
$query = $this->seller->table('users')
->limit(4,1)
->get();
echo "<pre>";
print_r($query->getResult());
}
The countAllResult method is used to aggregate the database query records.
public function order_data()
{
$query = $this->seller->table('users')
->countAllResults();
echo $query;
}
public function order_data()
{
$query = $this->seller->table('users')
->countAll();
echo $query;
}
My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in