<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Postmodel extends CI_Model {
function getcommentbypostid($postid){

if($postid!=null){
$this->db->select(" * from  comments where postid= '$postid'");

$bioquery = $this -> db -> get();


if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}


function getlostfoundbyid($id){

if($id!=null){
$this->db->select(" * from  lostfound where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
  

function getpostbyid($id){

if($id!=null){
$this->db->select(" * from  post where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
      public function getpostbyid1($cam_id)
    {
            $this->db->select('*');
        $this->db->from('post');
        $this->db->where('id',$cam_id); 
        $query = $this->db->get();
    return $query->result();
    } 

	
	
	function addnewcategory($data)
{
// Query to insert data in database
  //$regnumber = $data['regnumber'];
  
    $this->db->insert('category', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}
	
	
	
  function getcatelostfoundgorybyid($id){

if($id!=null){
$this->db->select(" * from  itemscategory where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
	function getcategorybyid($id){

if($id!=null){
$this->db->select(" * from  category where id= '$id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}

}


}
	
	
	
	
	
	
	function addnewlostfound($data)
{
// Query to insert data in database
  //$regnumber = $data['regnumber'];
  
    $this->db->insert('lostfound', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}
	
	
	
function addnewpost($data)
{
// Query to insert data in database
  //$regnumber = $data['regnumber'];
  
    $this->db->insert('post', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}

function addnewcomment($data)
{

  
    $this->db->insert('comments', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}
function populateadvert(){
 $this -> db -> select('*');
 //$this->db->where('id',1);
   $this -> db -> from('advert');
$this->db->order_by("id", "desc");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}

function populateallposts(){
 

  $this -> db -> select('*');

   $this -> db -> from('post');
  $this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}

function populateallquestions(){
 

  $this -> db -> select('*');

   $this -> db -> from('post');

$this->db->order_by("id", "desc");
 $query1 = $this -> db -> get();
 
 if($query1 -> num_rows() >0)

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}


function populatecategory(){
 $this -> db -> select('*');
 //$this->db->where('id',1);
   $this -> db -> from('category');
$this->db->order_by("id", "desc");

$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}
function populatelostfoundcategory(){
 $this -> db -> select('*');
 //$this->db->where('id',1);
   $this -> db -> from('itemscategory');


$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}


function addnewpostype($data)
{

  
    $this->db->insert('postype', $data);
  if ($this->db->affected_rows() > 0) 
      {
  return true;

      }


   else

   {

     return false;

   }


}
function populatepostype(){
 $this -> db -> select('*');
 //$this->db->where('id',1);
   $this -> db -> from('postype');


$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}
function populatelostfound(){
 $this -> db -> select('*');
 //$this->db->where('id',1);
   $this -> db -> from('lostfound');


$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();
   


}else{

  return false;
}




}






function populatepostimages($img_id){

if($img_id!=null){
$this->db->select(" * from uploadedimages where img_id= '$img_id'");
$this -> db -> limit(1);
$bioquery = $this -> db -> get();
if($bioquery->num_rows()>0){

   return $bioquery->result();

}else{

  return false;
}

}


}

function uploadimage($data)
  
{
   $img_id = $data['img_id'];
  if($img_id!=null){
     $this->db->where('img_id',$img_id);
 
   $qq = $this->db->get('uploadedimages');
    $this->db->trans_start();
   if ( $qq->num_rows() > 0 ) 
   {
      $this->db->where('img_id',$img_id);
      $this->db->update('uploadedimages',$data);
   } else {
      
      $this->db->insert('uploadedimages', $data);
      
   }



  
    $this->db->trans_complete(); 
       if($this->db->trans_status() === TRUE){// Check Transaction Result successful                          
 
  
  return true;

      }


   else

   {

     return false;

   }
    
} else

   {

     return false;

   }

}





   public function record_count() {
        return $this->db->count_all("systemusers");
    }


     public function populatepost($page){
        $offset = 5*$page;
        $limit =5;
        $sql = "select * from post  order by id desc  limit $offset ,$limit";
       // $this->db->order_by('id','desc');
        $result = $this->db->query($sql)->result();
	
        return $result;
    }





    function populatepost1()
 

{
  $this -> db -> select('*');

   $this -> db -> from('post');
     

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


   $query1 = $this -> db -> get();

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

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}
         


     public function populatemypost($id,$page){
        $offset = 5*$page;
        $limit =5;
        $sql = "select * from post where userid='$id' order by id desc  limit $offset ,$limit ";
      
        $result = $this->db->query($sql)->result();
		$this->db->order_by('id','desc');
        return $result;
    }
    function populatemypost1($id)
 

{
  $this -> db -> select('*');
        $this->db->order_by('id','desc');

   $this -> db -> from('post');
 $this->db->where('userid',$id);
        $this->db->order_by('id');


   $query1 = $this -> db -> get();

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

   {
  return $query1->result();

   }

   else

   {

     return false;

   }

}



}
 ?>