68 lines
2.2 KiB
PHP
Executable File
68 lines
2.2 KiB
PHP
Executable File
<?php
|
|
|
|
class M_data extends CI_Model {
|
|
|
|
// Function to check login credentials
|
|
public function cek_login($table, $where) {
|
|
return $this->db->get_where($table, $where);
|
|
}
|
|
|
|
// Function to retrieve data from the database
|
|
public function get_data($table) {
|
|
return $this->db->get($table);
|
|
}
|
|
|
|
// Function to insert data into the database
|
|
public function insert_data($data, $table) {
|
|
return $this->db->insert($table, $data);
|
|
}
|
|
|
|
// Function to edit data
|
|
public function edit_data($where, $table) {
|
|
return $this->db->get_where($table, $where);
|
|
}
|
|
|
|
// Function to update data in the database
|
|
public function update_data($where, $data, $table) {
|
|
$this->db->where($where);
|
|
return $this->db->update($table, $data);
|
|
}
|
|
|
|
// Function to delete data from the database
|
|
public function delete_data($where, $table) {
|
|
return $this->db->delete($table, $where);
|
|
}
|
|
|
|
public function get_user($where) {
|
|
// Ensure you are using the correct key from the $where array
|
|
$this->db->where('pengguna_id', $where['pengguna_id']); // Adjust based on your actual column name
|
|
$query = $this->db->get('pengguna'); // Ensure this table exists
|
|
return $query->row(); // Return a single row of user data
|
|
}
|
|
|
|
public function get_satkers()
|
|
{
|
|
return $this->db->get('satker')->result(); // Mengambil semua data satker
|
|
}
|
|
|
|
// Fungsi untuk mendapatkan semua pengguna dengan nama satker
|
|
public function get_all_pengguna_with_satker() {
|
|
$this->db->select('pengguna.*, satker.nama_satker');
|
|
$this->db->from('pengguna');
|
|
$this->db->join('satker', 'satker.satker_id = pengguna.satker_id', 'left'); // pakai nama tabel di kedua sisi
|
|
return $this->db->get()->result();
|
|
}
|
|
|
|
public function get_pengguna_by_id($id)
|
|
{
|
|
$this->db->select('pengguna.*, satker.nama_satker');
|
|
$this->db->from('pengguna');
|
|
$this->db->join('satker', 'pengguna.satker_id = satker.satker_id', 'left');
|
|
$this->db->where('pengguna_id', $id);
|
|
return $this->db->get();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|