I build online shop using codeigniter. I have product catalogs. When the user clicks each catalog, it must show the detailed information in another view. But, I have no idea on what I suppose to do.
Can anybody give me example code, I mean code in controller and model.
This is my view
public function detail($page = 'detail') {
$data['title'] = ucfirst($page);
$this->cart_model->test($id);
$data['produk'] = $this->cart_model->test($id);
print_r($data['produk']);die();
$this->load->view('user/templates/header', $data);
$this->load->view('user/templates/navigation', $data);
$this->load->view('user/pages/' . $page, $data);
$this->load->view('user/templates/footer', $data);
}
my model
public function test($id) {
$query = $this->db->query('SELECT * FROM PRODUK WHERE id_produk = ' . $id);
return $query->result_array();
}
this is my view
<?php foreach ($produk as $data): ?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="images">
<a href="" class="img-responsive"><img src="/sjpro/asset/user/img/produk<?php echo $data['gambar'];?>"></a>
</div>
</div>
<div class="col-lg-8 col-md-4 col-sm-4">
<h3><?php echo $data['nama_produk']?></h3>
<div class="price-detail">Harga <span class="price-detail-color"><?php echo $data['harga_produk']?></span></div>
<span class="label label-success"><?php echo $data['status_produk']?></span>
<div class="well well-lg">
<form action="" class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label">Jumlah</label>
<div class="col-lg-3">
<input type="number" step="1" min="1" name="quantity" value="1" class="form-control" size="2">
</div>
<button type="button" class="btn btn-success btn-lg pull-right" data-toggle="modal" data-target="#modal-beli">BELI</button>
</div>
</form>
</div>
if you need to get which product user select just use
<a>
tag with the product id.<a href="<?php echo base_url()?>index.php/controller/function(preview)/<?php echo $data['id']?>">
.so your function know which product to be selected.
then catch this with tour controller
in Model
this will select all details form id which you passed to model (
$id
)in view