<?php
 class Model_crud extends CI_Model {
 	public function __construct() {
		
	}

	public function ambil_data($kunci,$tabel,$urut=array()) {
		$this->db->from($tabel);
		$this->db->where($kunci);
		if (is_array($urut)) {
			foreach ($urut as $key => $value) {
				$this->db->order_by($key,$value);
			}
		}
		$query=$this->db->get();
		return $query;
	}

	public function join_tabel($selek,$kunci,$tabel,$arrjoin=array(),$urut=array()) {
		if ($selek) {
			$this->db->select($selek);
		}
		$this->db->from($tabel);
		if (is_array($arrjoin)) {
			foreach ($arrjoin as $key => $value) {
				$this->db->join($key,$value);
			}
		}
		$this->db->where($kunci);
		if (is_array($urut)) {
			foreach ($urut as $key => $value) {
				$this->db->order_by($key,$value);
			}
		}
		$query=$this->db->get();
		return $query;
	}

	public function tambah_data($tabel,$data) {
		$this->db->insert($tabel,$data);		
	}

	public function update_data($kunci,$tabel,$data) {
		$this->db->where($kunci);
		$this->db->update($tabel,$data);		
	}

	public function hapus_data($kunci,$tabel) {
		$this->db->where($kunci);
		$this->db->delete($tabel);
	}
}
?>