If we have to return specific data. So we use the ware function. In this function, we pass some parameters, from which the data is filtered and returned. Some where function provide by codeingiter : where, orWhere, wherein, orWhereIn, whereNotIn, orWhereNotIn.
public function custom_data()
{
$query = $this->seller->table('users')
->where('salary',200)
->where('age',20)
->get();
echo "<pre>";
print_r($query->getResult());
}
We can also include operators in custom key / value. Like as :
public function custom_data()
{
$query = $this->seller->table('users')
->where('age>',20)
->get();
echo "<pre>";
print_r($query->getResult());
}
public function custom_data()
{
$query = $this->seller->table('users')
->where('age>',20)
->where('salary>=',5000)
->get();
echo "<pre>";
print_r($query->getResult());
}
In the ware function, we can pass the parameter in the array format.
public function custom_data()
{
$condition = ['age>'=>20,'salary>='=>5000];
$query = $this->seller->table('users')
->where($condition)
->get();
echo "<pre>";
print_r($query->getResult());
}
public function custom_data()
{
$query = $this->seller->table('users')
->where(['age>'=>20,'salary>='=>5000])
->get();
echo "<pre>";
print_r($query->getResult());
}
If the value ware function is not returning, then we use more ware function.
public function custom_data()
{
$query = $this->seller->table('users')
->where('age',20)
->orWhere('age',22)
->get();
echo "<pre>";
print_r($query->getResult());
}
In ware in function, we pass the value in the array format and return the data.
public function custom_data()
{
$age_list = array(20,21,22);
$query = $this->seller->table('users')
->whereIn('age',$age_list)
->get();
echo "<pre>";
print_r($query->getResult());
}
public function custom_data()
{
$age_list = array(21,22);
$query = $this->seller->table('users')
->where('age',20)
->orWhereIn('age',$age_list)
->get();
echo "<pre>";
print_r($query->getResult());
}
We use the where_not_in function to not match the value.
public function custom_data()
{
$age_list = array(21,22);
$query = $this->seller->table('users')
->WhereNotIn('age',$age_list)
->get();
echo "<pre>";
print_r($query->getResult());
}
public function custom_data()
{
$age_list = array(21,22);
$new_list = array(20,25);
$query = $this->seller->table('users')
->orWhereNotIn('age',$age_list)
->get();
echo "<pre>";
print_r($query->getResult());
}
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