Postingan lainnya
modal bootstrap codeigniter tidak mau menampilkan data
halo para master saya mau bertanya... saya baru saja belajar modal di codeigniter, dan saya mencoba download beberapa aplikasi. dan berusaha edit2 dan menambahkan beberapa halaman. ketika saya mau menampilkan detail dari data dengan modal data tersebut tidak mau tampil... tolong bantuannya para master...
dan ini code pada halaman yang ada modalnya
<?php
$uri4 = $this->uri->segment(4);
?>
<html>
<head>
<title>Live CRUD</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css'); ?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/sweetalert/sweetalert.css'); ?>">
<script type="text/javascript" src="<?php echo base_url('assets/jquery.js'); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/bootstrap/js/bootstrap.min.js'); ?>"></script>
<div class="col-md-10 col-xs-12">
<div class="panel panel-info">
<div class="panel-heading">Daftar Hasil Tes
<div class="tombol-kanan">
<a href='<?php echo base_url(); ?>adm/hasil_ujian_cetak/<?php echo $uri4; ?>' class='btn btn-info btn-sm' target='_blank'><i class='glyphicon glyphicon-print'></i> Cetak</a>
</div>
</div>
<div class="panel-body">
<div class="col-lg-12 alert alert-warning" style="margin-bottom: 20px">
<div class="col-md-6">
<table class="table table-bordered" style="margin-bottom: 0px">
<tr><td>Mata Pelajaran</td><td><?php echo $detil_tes->namaMapel; ?></td></tr>
<tr><td>Nama Guru</td><td><?php echo $detil_tes->nama_guru; ?></td></tr>
<tr><td width="30%">Nama Ujian</td><td width="70%"><?php echo $detil_tes->nama_ujian; ?></td></tr>
<tr><td>Waktu</td><td><?php echo $detil_tes->waktu; ?> menit</td></tr>
</table>
</div>
<!--<div class="col-md-2"></div>-->
<div class="col-md-6">
<table class="table table-bordered" style="margin-bottom: 0px">
<tr><td width="30%">Jumlah Soal</td><td><?php echo $detil_tes->jumlah_soal; ?></td></tr>
<tr><td>Tertinggi</td><td><?php echo $statistik->max_; ?></td></tr>
<tr><td>Terendah</td><td><?php echo $statistik->min_; ?></td></tr>
<tr><td>Rata-rata</td><td><?php echo number_format($statistik->avg_); ?></td></tr>
</table>
</div>
</div>
<table class="table table-bordered" id="datatabel">
<thead>
<tr>
<th width="5%">No</th>
<th width="20%">Nama Peserta</th>
<th width="10%">Jumlah Benar</th>
<th width="10%">Nilai</th>
<th width="10%">Nilai Bobot</th>
<th width="50%">Jawaban</th>
<th width="50%">uri</th>
<th width="10%">Aksi</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal fade" id="h_ujian" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 id="myModalLabel">Edit Jawaban Siswa</h4>
</div>
<div class="modal-body">
<form name="e_jwb" id="e_jwb" onsubmit="return m_ejawaban_s();">
<input type="text" name="idsiswa" id="idsiswa" value="0">
<table class="table table-form">
<tr><td style="width: 25%">Nama</td><td style="width: 75%"><input type="text" class="form-control" name="nama" id="nama" required></td></tr>
<tr><td style="width: 25%">List Jawaban</td><td style="width: 75%"><input type="textarea" class="form-control" name="list_jawaban" id="list_jawaban" required></td></tr>
<tr><td style="width: 25%">Jumlah Benar</td><td style="width: 75%"><input type="text" class="form-control" name="jml_benar" id="jml_benar" required></td></tr>
<tr><td style="width: 25%">Nilai</td><td style="width: 75%"><input type="text" class="form-control" name="nilai" id="nilai" required></td></tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-primary"><i class="fa fa-check"></i> Simpan</button>
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="fa fa-minus-circle"></i> Tutup</button>
</div>
</form>
</div>
</div>
</div>
ini kode jsnya saya taruh di file aplikasi.js
function m_ejwb_e(id) {
$("#h_ujian").modal('show');
$.ajax({
type: "GET",
url: base_url+"adm/h_ujian/det/"+id,
success: function(data) {
$("#idsiswa").val(data.idsiswa);
$("#nama").val(data.nama);
$("#list_jawaban").val(data.list_jawaban);
$("#jml_benar").val(data.jml_benar);
$("#nilai").val(data.nilai);
$("#nama").focus();
}
});
return false;
}
dan ini controllernya
public function h_ujian() {
$this->cek_aktif();
cek_hakakses(array("guru","admin"), $this->session->userdata('admin_level'));
//var def session
$a['sess_level'] = $this->session->userdata('admin_level');
$a['sess_user'] = $this->session->userdata('admin_user');
$a['sess_konid'] = $this->session->userdata('admin_konid');
//var def uri segment
$uri2 = $this->uri->segment(2);
$uri3 = $this->uri->segment(3);
$uri4 = $this->uri->segment(4);
$uri5 = $this->uri->segment(5);
//var post from json
$p = json_decode(file_get_contents('php://input'));
//return as json
$jeson = array();
$wh_1 = $a['sess_level'] == "admin" ? "" : " AND a.id_guru = '".$a['sess_konid']."'";
//$a['data'] = $this->db->query($wh_1)->result();
$a['p_mapel'] = obj_to_array($this->db->query("SELECT * FROM m_mapel")->result(), "id,nama");
$a['data'] = $this->db->query("SELECT tr_ikut_ujian.* FROM tr_ikut_ujian")->result();
if ($uri3 == "det") {
$a['detil_tes'] = $this->db->query("SELECT m_mapel.nama AS namaMapel, m_guru.nama AS nama_guru,
tr_guru_tes.*
FROM tr_guru_tes
INNER JOIN m_mapel ON tr_guru_tes.id_mapel = m_mapel.id
INNER JOIN m_guru ON tr_guru_tes.id_guru = m_guru.id
WHERE tr_guru_tes.id = '$uri4'")->row();
$a['statistik'] = $this->db->query("SELECT MAX(nilai) AS max_, MIN(nilai) AS min_, AVG(nilai) AS avg_
FROM tr_ikut_ujian
WHERE tr_ikut_ujian.id_tes = '$uri4'")->row();
//$a['hasil'] = $this->db->query("")->result();
$a['p'] = "m_guru_tes_hasil_detil";
//echo $this->db->last_query();
} else if ($uri3 == "data_det") {
$start = $this->input->post('start');
$length = $this->input->post('length');
$draw = $this->input->post('draw');
$search = $this->input->post('search');
$d_total_row = $this->db->query("
SELECT a.id
FROM tr_ikut_ujian a
INNER JOIN m_siswa b ON a.id_user = b.id
WHERE a.id_tes = '$uri4'
AND b.nama LIKE '%".$search['value']."%'")->num_rows();
$q_datanya = $this->db->query("
SELECT a.id,a.id_user as idsiswa, b.nama,a.list_jawaban, a.nilai, a.jml_benar, a.nilai_bobot
FROM tr_ikut_ujian a
INNER JOIN m_siswa b ON a.id_user = b.id
WHERE a.id_tes = '$uri4'
AND b.nama LIKE '%".$search['value']."%' ORDER BY a.id DESC LIMIT ".$start.", ".$length."")->result_array();
$data = array();
$no = ($start+1);
foreach ($q_datanya as $d) {
$data_ok = array();
$data_ok[0] = $no++;
$data_ok[1] = $d['nama'];
$data_ok[2] = $d['jml_benar'];
$data_ok[3] = $d['nilai'];
$data_ok[4] = $d['nilai_bobot'];
$data_ok[5] = $d['list_jawaban'];
$data_ok[6] = $d['idsiswa'];
$data_ok[7] = '
<div class="btn-group">
<a href="'.base_url().'adm/h_ujian/batalkan_ujian/'.$d['id'].'/'.$this->uri->segment(4).'" class="btn btn-danger btn-xs" onclick="return confirm(\'Anda yakin...?\');"><i class="glyphicon glyphicon-remove" style="margin-left: 0px; color: #fff"></i> Batalkan Ujian</a>
<a href="#" onclick="return m_ejwb_e('.$d['idsiswa'].');" class="btn btn-info btn-xs"><i class="glyphicon glyphicon-pencil" style="margin-left: 0px; color: #fff"></i> Edit</a>
</div>';
$data[] = $data_ok;
}
$json_data = array(
"draw" => $draw,
"iTotalRecords" => $d_total_row,
"iTotalDisplayRecords" => $d_total_row,
"data" => $data
);
j($json_data);
exit;
} else if ($uri3 == "batalkan_ujian") {
$this->db->query("DELETE FROM tr_ikut_ujian WHERE id = '$uri4'");
redirect('adm/h_ujian/det/'.$uri5);
} else if ($uri3 == "data") {
$start = $this->input->post('start');
$length = $this->input->post('length');
$draw = $this->input->post('draw');
$search = $this->input->post('search');
$d_total_row = $this->db->query("SELECT a.id FROM tr_guru_tes a
INNER JOIN m_mapel b ON a.id_mapel = b.id
INNER JOIN m_guru c ON a.id_guru = c.id
WHERE (a.nama_ujian LIKE '%".$search['value']."%' OR b.nama LIKE '%".$search['value']."%' OR c.nama LIKE '%".$search['value']."%') ".$wh_1."")->num_rows();
//echo $this->db->last_query();
$q_datanya = $this->db->query("SELECT a.*, b.nama AS mapel, c.nama AS nama_guru FROM tr_guru_tes a
INNER JOIN m_mapel b ON a.id_mapel = b.id
INNER JOIN m_guru c ON a.id_guru = c.id
WHERE (a.nama_ujian LIKE '%".$search['value']."%' OR b.nama LIKE '%".$search['value']."%' OR c.nama LIKE '%".$search['value']."%') ".$wh_1." ORDER BY a.id DESC LIMIT ".$start.", ".$length."")->result_array();
$data = array();
$no = ($start+1);
foreach ($q_datanya as $d) {
$data_ok = array();
$data_ok[0] = $no++;
$data_ok[1] = $d['nama_ujian'];
$data_ok[2] = $d['nama_guru'];
$data_ok[3] = $d['mapel'];
$data_ok[4] = $d['jumlah_soal'];
$data_ok[5] = $d['waktu']." menit";
$data_ok[6] = '<a href="'.base_url().'adm/h_ujian/det/'.$d['id'].'" class="btn btn-info btn-xs"><i class="glyphicon glyphicon-search" style="margin-left: 0px; color: #fff"></i> Lihat Hasil</a>
';
$data[] = $data_ok;
}
$json_data = array(
"draw" => $draw,
"iTotalRecords" => $d_total_row,
"iTotalDisplayRecords" => $d_total_row,
"data" => $data
);
j($json_data);
exit;
}
//$a['data'] = $this->db->query("SELECT tr_ikut_ujian.* FROM tr_ikut_ujian")->result();
else if ($uri3 == "editjawaban") {
$a = $this->db->query("SELECT * from tr_ikut_ujian WHERE id_user='$idsiswa'")->row();
j($json_data);
exit;
}
else {
$a['p'] = "m_guru_tes_hasil";
}
$this->load->view('aaa', $a);
}
2 Jawaban:
ini pakai bootstrap kan? saya ga liat button aksi buat edit di kodinganya gan. coba tambahin ini. kalo blum bisa coba pindahin script js nya jadi dibawah,jangan didalam header. yang saya tahu cuman itu gan. mungkin membantu.
//tambahin button dengan data-target di isi id dari modalnya "h_ujian" seperti //dibawah
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#h_ujian">
Edit
</button>
<div class="modal fade" id="h_ujian" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 id="myModalLabel">Edit Jawaban Siswa</h4>
</div>
<div class="modal-body">
<form name="e_jwb" id="e_jwb" onsubmit="return m_ejawaban_s();">
<input type="text" name="idsiswa" id="idsiswa" value="0">
<table class="table table-form">
<tr><td style="width: 25%">Nama</td><td style="width: 75%"><input type="text" class="form-control" name="nama" id="nama" required></td></tr>
<tr><td style="width: 25%">List Jawaban</td><td style="width: 75%"><input type="textarea" class="form-control" name="list_jawaban" id="list_jawaban" required></td></tr>
<tr><td style="width: 25%">Jumlah Benar</td><td style="width: 75%"><input type="text" class="form-control" name="jml_benar" id="jml_benar" required></td></tr>
<tr><td style="width: 25%">Nilai</td><td style="width: 75%"><input type="text" class="form-control" name="nilai" id="nilai" required></td></tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-primary"><i class="fa fa-check"></i> Simpan</button>
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="fa fa-minus-circle"></i> Tutup</button>
</div>
</form>
</div>
</div>
</div>
Terima Kasih atas responnya gan @charlysitumorang. Untuk botton modal ada di controller gan, ini scriptnya..
if ($uri3 == "det") {
$a['detil_tes'] = $this->db->query("SELECT m_mapel.nama AS namaMapel, m_guru.nama AS nama_guru,
tr_guru_tes.*
FROM tr_guru_tes
INNER JOIN m_mapel ON tr_guru_tes.id_mapel = m_mapel.id
INNER JOIN m_guru ON tr_guru_tes.id_guru = m_guru.id
WHERE tr_guru_tes.id = '$uri4'")->row();
$a['statistik'] = $this->db->query("SELECT MAX(nilai) AS max_, MIN(nilai) AS min_, AVG(nilai) AS avg_
FROM tr_ikut_ujian
WHERE tr_ikut_ujian.id_tes = '$uri4'")->row();
//$a['hasil'] = $this->db->query("")->result();
$a['p'] = "m_guru_tes_hasil_detil";
//echo $this->db->last_query();
} else if ($uri3 == "data_det") {
$start = $this->input->post('start');
$length = $this->input->post('length');
$draw = $this->input->post('draw');
$search = $this->input->post('search');
$d_total_row = $this->db->query("
SELECT a.id
FROM tr_ikut_ujian a
INNER JOIN m_siswa b ON a.id_user = b.id
WHERE a.id_tes = '$uri4'
AND b.nama LIKE '%".$search['value']."%'")->num_rows();
$q_datanya = $this->db->query("
SELECT a.id,a.id_user as idsiswa, b.nama,a.list_jawaban, a.nilai, a.jml_benar, a.nilai_bobot
FROM tr_ikut_ujian a
INNER JOIN m_siswa b ON a.id_user = b.id
WHERE a.id_tes = '$uri4'
AND b.nama LIKE '%".$search['value']."%' ORDER BY a.id DESC LIMIT ".$start.", ".$length."")->result_array();
$data = array();
$no = ($start+1);
foreach ($q_datanya as $d) {
$data_ok = array();
$data_ok[0] = $no++;
$data_ok[1] = $d['nama'];
$data_ok[2] = $d['jml_benar'];
$data_ok[3] = $d['nilai'];
$data_ok[4] = $d['nilai_bobot'];
$data_ok[5] = $d['list_jawaban'];
$data_ok[6] = $d['idsiswa'];
$data_ok[7] = '
<div class="btn-group">
<a href="'.base_url().'adm/h_ujian/batalkan_ujian/'.$d['id'].'/'.$this->uri->segment(4).'" class="btn btn-danger btn-xs" onclick="return confirm(\'Anda yakin...?\');"><i class="glyphicon glyphicon-remove" style="margin-left: 0px; color: #fff"></i> Batalkan Ujian</a>
<a href="#" onclick="return m_ejwb_e('.$d['idsiswa'].');" class="btn btn-info btn-xs"><i class="glyphicon glyphicon-pencil" style="margin-left: 0px; color: #fff"></i> Edit</a>
</div>';
$data[] = $data_ok;
}
$json_data = array(
"draw" => $draw,
"iTotalRecords" => $d_total_row,
"iTotalDisplayRecords" => $d_total_row,
"data" => $data
);
j($json_data);
exit;
}