Postingan lainnya
datanya gak ke edit
kode buat edit get_edit(input::get('kode')); //var_dump($tables);
$_table = $tables; //var_dump($_table['kode']);
if( input::get('submit') ){
//1. memanggil objek validasi $validation = new validation();
//2. metode check $validation = $validation->check(array( 'judul' => array('required' => true,), 'pengarang' => array('required' => true,), 'tahun' => array('required' => true,) ));
if($validation->passed()){ $library->edit_data(array( 'judul' => input::get('judul'), 'tahun' => input::get('tahun'), 'pengarang' => input::get('pengarang') ),$_table['kode'] );
redirect::to('index'); }else{ $errors = $validation->errors(); }
}
require_once 'templates/view.php'; ?>
Silahkan Diedit
Judul Buku
pengarang Buku
Tahun Buku
proses editnya public function cek_data($kode) { //var_dump($kode); //die($kode); $data =$this->_db->get_edit1('book','kode',$kode); if(empty($data) )return false; else return true; } public function edit_data($fields = array(), $kode) { //var_dump($kode); //die(); if( $this->_db->update('book', $fields, $kode) ) return true; else return false;
}
public function get_edit($kode) { //var_dump($kode); if($this->cek_data($kode)) return $this->_db->get_edit1('book','kode',$kode); else die('kode tidak ada'); }
proses ke databasenya public function update($table ,$fields, $kode) { //mengambil nilai $ValuesArrays = array(); $i = 0;
foreach($fields as $key=>$values){ if(is_int($values) ){ $ValuesArrays[$i] = $key . "=" . $this->escape($values); }else{ $ValuesArrays[$i] = $key . "='". $this->escape($values) ."'"; } $i++; } public function get_edit1($table,$column='',$value='') { if(!is_int($value) ) $value = "'". $value . "'";
if($column !=''){ $query = "SELECT * from $table WHERE $column= $value"; $result = $this->mysqli->query($query);
while($row = $result->fetch_assoc()){ return $row; } }else{ $query = "SELECT * from $table"; $result = $this->mysqli->query($query);
while($row = $result->fetch_assoc()){ $results[] = $row; } return $results; } }
3 Jawaban:
mungkin bisa di pakaikan tag kode, karena agak sedikit rumit baca nya