Fetch data with where | orWhere | wherein | orWhereIn | whereNotIn

Deepak Tailor Image
Deepak Tailor - Oct 28 2020
Fetch data with where | orWhere | wherein | orWhereIn | whereNotIn

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.

Simple key/value in where()
public function custom_data()
{
	$query = $this->seller->table('users')
			 ->where('salary',200)
			 ->where('age',20)
			 ->get();
	echo "<pre>";
	print_r($query->getResult());
}
Custom key/value in where()

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());
}
Associative array in where()

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());
}
orWhere function

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());
}
whereIn function

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());
}
orWhereIn function
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());
}
whereNotIn function

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());
}
orWhereNotIn function
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());
}
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry for the last 5 years. For professional and customize web development, you can send inquiry on our email.
----
You can contact him at support@fulstackdev.com