<?php 

class posts_model extends CI_model

 {

   

	



		function get_posts($type,$status,$rec_no)

		{

		  $this->db->where('module',$type);

		  if($status=='active')

		  {

		  $this->db->where('active','yes');

		  }

		  if($status=='nonactive')

		  {

		  $this->db->where('active','no');

		  }

			  if($type='portfolio' or $type='clients')

			  {

			   $this->db->order_by("p_order", "asc"); 

			  }

			  else

			  {

			  $this->db->order_by("id", "desc"); 

			  }

		  $query=$this->db->get('posts',$rec_no,$this->uri->segment(5)); // select * from posts where module='$type'  limit $rec_no

		  

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

		    return $query->result(); 

		     return FALSE;



		}

		

		function get_num_posts($type,$status)

		{

		  $this->db->where('module',$type);

		  if($status=='active')

		  {

		  $this->db->where('active','yes');

		  }

		  if($status=='nonactive')

		  {

		  $this->db->where('active','no');

		  }

		  $this->db->order_by("id", "desc"); 

		  $query=$this->db->get('posts'); // select * from posts where module='$type' 

		  

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

		    return $query->num_rows(); 

		     return FALSE;



		}



		

		

		function add_new_post($data)

		{

		$q=$this->db->insert('posts',$data);

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

		}

		function add_new_job($data)

		{

		$q=$this->db->insert('jobs',$data);

		return $q;

		}

		



		

		function update_post($data,$id)

		{

		$this->db->where('id',$id);

		$q=$this->db->update('posts',$data);

		//if($q->num_rows() > 0)

		return $q; 

		//return FALSE;

		}

		

		function update_job($data,$id)

		{

		$this->db->where('job_id',$id);

		$q=$this->db->update('jobs',$data);

		//if($q->num_rows() > 0)

		return $q; 

		//return FALSE;

		}

		

		





	

	

	



}

