<?php
class M_tamu extends CI_Model{

		function tampilall(){
		$query = $this->db->query("SELECT * FROM tamu as a 		
															JOIN kategori as b ON b.idkategori = a.idkategori 
															JOIN bidang as c ON c.idbidang = b.idbidang 
															ORDER BY  a.tanggal  DESC ");		
		return $query;
		}

		function tampil(){
		$date = date('Y-m-d');
		$query = $this->db->query("SELECT * FROM tamu as a 
															JOIN kategori as b ON b.idkategori = a.idkategori 
															JOIN bidang as c ON c.idbidang = b.idbidang 
															WHERE a.tanggal LIKE '%$date%'
															ORDER BY  a.tanggal  DESC ");		
		return $query;
		}
		
		function edit($id){
		$query = $this->db->query("SELECT * FROM tamu as a 
															JOIN kategori as b ON b.idkategori = a.idkategori 
															JOIN bidang as c ON c.idbidang = b.idbidang 
															WHERE idtamu = '$id'
															ORDER BY  a.tanggal  DESC ");		
		return $query;
		}

		function getNewData(){
		$date = date('Y-m-d');
		$this->db->select('*');
		$this->db->from('tamu');
		$this->db->join('kategori', 'kategori.idkategori = tamu.idkategori');	
		$this->db->where('tamu.tanggal LIKE', '%'.$date.'%');			
		$this->db->order_by("tamu.tanggal", "DESC");
		$query = $this->db->get();
		return $query->result();
		}
		
		function in($data_save,$table){
					$this->db->insert($table,$data_save);
		} 	
		function update($where,$data,$table){
				$this->db->where($where);
				$this->db->update($table,$data);
		}	
			function hapus($where,$table){
				$this->db->where($where);
				$this->db->delete($table);
		}			
}