Assalamu'alaykum agan2..
ane mau konsul lagi gan, masalah data di ci..
kalo mau bikin while dalam while itu di ci gimana yaa gan?berarti kan foreach dalam foreach yaa??
kurang lebih ane mau bikin kaya gini
jadi, di dalam nama barang ada detail2 harga lagi..
nii, model ane gan:
Quote:
function get_harga_barang() {
$this->db->where('del','0');
$this->db->order_by('nama','ASC');
$query = $getData = $this->db->get('barang');
if($getData->num_rows() > 0)
return $query;
else
return null;
}
function get_harga_barang_detail($id_barang) {
$this->db->select('*');
$this->db->from('harga');
$this->db->join('supplier', 'supplier.id_supplier=harga.id_supplier');
$this->db->where('harga.id_barang', $id_barang);
$this->db->order_by('id_harga', 'desc');
$query = $getData = $this->db->get();
if($getData->num_rows() > 0)
return $query;
else
return null;
}
controller :
Quote:
public function index()
{
$data['judul'] = 'Harga Barang';
$data['harga_barang'] = $this->m_harga_barang->get_harga_barang();
$data['harga_barang_detail'] = $this->m_harga_barang->get_harga_barang_detail();
$this->load->view('harga_barang', $data);
}
view nya:
Quote:
<table class="table table-striped table-bordered table-hover dataTables-example" >
<thead>
<tr>
<th>NO</th>
<th>NAMA BARANG</th>
<th>JENIS BARANG</th>
<th>SATUAN</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
<?php
$no=1;
foreach($harga_barang->result() as $row):?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo($row->nama);?></td>
<td><?php echo($row->jenis_barang);?></td>
<td><?php echo($row->sat);?></td>
<td>
<?php
if($this->session->userdata('level')=="1" || $this->session->userdata('level')=="3"){
echo anchor('harga_barang/tambah_harga/'.$row->id_barang,"<span class='glyphicon glyphicon-plus'></span>");
}
?>
</td>
</tr>
<tr><td></td><td>
<table>
<tr><th>Supplier</th><th>Harga</th><th>Berlaku Harga</th><th>Last Update</th><th></th></tr>
<?php foreach($harga_barang_detail->result() as $rowx):?>
<tr>
<td><?php echo($rowx->nama);?></td>
<td><?php echo($rowx->mt);?></td>
<td><?php echo($rowx->harga);?></td>
<td><?php echo($rowx->edited_by);?></td>
<td>
<?php
if($this->session->userdata('level')=="1" || $this->session->userdata('level')=="3"){
echo anchor('harga_barang/edit_harga/'.$rowx->id_barang,"<span class='glyphicon glyphicon-plus'></span>");
}
?>
</td>
</tr>
<?php endforeach; ?>
</table></td></tr>
<?php $no++;
endforeach; ?>
error nya gan:
ini error di dalem foreach yg kedua:
mohon pencerahannya agan2 mastah ci...
