<?php



class Db_model extends CI_Model

{




   
	

	function get_count($table)

	{

		$count = $this->db->count_all_results($table);

		

		if($count)

		 return $count;

		

		else

		 return '0';

	}

	

	

	function get_all($table)

	{

		$query = $this->db->get($table);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	function get_all_by_order($table,$order_field,$order)

	{

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get($table);

		

		if($query->num_rows()>0) 

		

		 return $query->result_array();

		

		else

		 return false;

	}

	

	

	

	/*function get_where_by_ordersubq($table,$condition,$order_field,$order)

	{

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,'select first_name,email,address,tel,mobile,(select location from shop_location where lid=shop_checkoutusers.location)locationname where active=1');

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}*/

	

	

	

	function get_all_by_order_limit($table,$order_field,$order,$limit_from,$select_count)

	{

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get($table,$select_count,$limit_from);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	

	function get_where($table,$condition)

	{ 

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

		 

	}

	

	function get_where_by_order($table,$condition,$order_field,$order)

	{ 

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		

		 return $query->result_array();

		

		else

		 return false;

	}






	function get_where_by_order_seearch($table,$condition,$order_field,$order)

	{ 
        $this->db->order_by('featured','DESC') ;
		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		

		 return $query->result_array();

		

		else

		 return false;

	}





function information($table,$condition)

	{ 


foreach ($condition as $value) {
  $ids.="$value".",";
  
}

 $finalids=rtrim($ids,',');

$query = $this->db->query("SELECT * FROM `shop_product` WHERE `aid` IN (".$finalids.")");

if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;


	}










	

	function get_where_by_order_limit($table,$condition,$order_field,$order,$limit)

	{

		$cv=$this->db->order_by($order_field,$order) ;

		$query = $this->db->get($table,$limit);

	

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	function get_where_by_order_limit1($table,$condition,$order_field,$order)

	{

		$cv=$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,$condition);

	

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}
	
	
	function get_where_by_order_limit2($table,$condition,$order_field,$order,$limit)

	{

		$cv=$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,$condition,$limit);

	

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}




	

	function get_where_by_order_group($table,$condition,$order_field,$order,$group)

	{

		$this->db->group_by($group) ;

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	



	function get_by_order_group($table,$order_field,$order,$group)

	{

		$this->db->group_by($group) ;

		$this->db->order_by($order_field,$order) ;

		$query = $this->db->get($table);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	





	function get_by_id($table,$id,$id_val)

	{

		$query = $this->db->get_where($table,array($id=>$id_val),1);

		

		if($query->num_rows()==1)

		 return $query->row();

		

		else

		 return false;

		 

	}

	

	function get_one($table='',$cond=array())

	{

		$query = $this->db->get_where($table,$cond,1);

  

		if($query->num_rows()==1)

		 return $query->row();

		

		else

		 return false;

		 

	}



	

	function get_by_query($query_string)

	{

		$query = $this->db->query($query_string);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	

	function get_by_limit($table,$count,$from)

	{

		$query = $this->db->get($table,$count,$from);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	function get_field($field,$table,$condition)

	{

		$this->db->select($field) ;

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

	}

	

	

	function insert($table,$data)

	{

		if($this->db->insert($table,$data))

		{

		

			return $this->db->insert_id();

			

		}

		else

		{

			return false;

		}

	}

	

	

	

	

	

	

	function insert_batch($table,$data_array_of_array)

	{   

	

		if($this->db->insert_batch($table,$data_array_of_array))

			return true;

			

		else

			return false;        

	}

	

	

	function update($table,$data,$condition)

	{

	

		$this->db->update($table,$data,$condition);

	}

		

		

	function delete($table,$condition)

	{

		$this->db->delete($table,$condition);

	}

	

	function max_orderid()

	{

		$this->db->select_max('order_id','order_id');

		$query = $this->db->get('shop_order') ;

		

		if($query->num_rows()==1)

			return $query->row();

		

		else

			return false;

	}

	



	function max_shoporderid($table,$con)

	{

		$this->db->select_max($con,$con);

		$query = $this->db->get($table) ;

		

		if($query->num_rows()==1)

			return $query->row();

		

		else

			return false;

	}	

function get_where_like_only($table,$condition,$keyword1)

	{ 

		$this->db->like('title',$keyword1);

		

		

		$query = $this->db->get_where($table,$condition);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

		 

	}

	

	function get_like_only($table,$keyword1)

	{ 

		$this->db->like('title',$keyword1);

		

		

		$query = $this->db->get($table);

		

		if($query->num_rows()>0)

		 return $query->result_array();

		

		else

		 return false;

		 

	}
	
	
	
	
	 public function get_count_pagi($table) {
        return $this->db->count_all($table);
    }
	
	
	 public function get_authors($table,$limit, $start,$order_field,$order) {
		 
		 $this->db->order_by('featured','DESC') ;
		 $this->db->order_by($order_field,$order) ;
        $this->db->limit($limit, $start);
		
        $query = $this->db->get_where($table,$condition);

        return $query->result();
    }
	
	
	
	
	 public function get_all_data($table,$condition) {
        $this->db->limit();
        $query = $this->db->get_where($table,$condition);

        return $query->result();
    }
	
	
	public function get_all_data_order($table,$condition,$order_field,$order) {
		
		$this->db->order_by('featured','DESC') ;
		$this->db->order_by($order_field,$order) ;
        $this->db->limit();
        $query = $this->db->get_where($table,$condition);

        return $query->result();
    }
	
	
	
	public function get_all_data_order_order($table,$condition,$order_field,$order) {
		
		$this->db->order_by('featured','DESC') ;
		$this->db->order_by($order_field,$order) ;
		
		
		//$array_of_ordered_ids = array(1,0);
		//$this->db->where_in('featured', $array_of_ordered_ids);
		
		
		
		
       // $this->db->limit();
        $query = $this->db->get_where($table,$condition);
		

        return $query->result();
    }
	
	
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	

}

