Welcome Guest, Not a member yet? Register   Sign In
Can't show product from db by id
#1

[eluser]mirag3[/eluser]
Hi a have a problem, i cant show product by id.

I have connected db and loaded database library. Structure of table products: id_product, name, label.

Product(controler).php:

class Product extends CI_Controller {

public function show_product($id_product)
{
$this->load->model('product_model');
$data['product'] = $this->product_model->Show_product();
$this->load->view('product_view', $data);
}
}

Product_view:

<?= $obj->name ?>
<?= $obj->id_product ?>
<?= $obj->label ?>

Product_model:


class Product_model extends CI_Model {

function Show_product()
{
$data['id_product']
$q = $this->db->get('products');

return $q->result();
}

}

I have to url as http://localhost/shop/product/$id , how must be routing?

Im newbie in codeigniter, help please.
Thanks
#2

[eluser]InsiteFX[/eluser]
CodeIgniter Users Guide - URI Routing
#3

[eluser]mirag3[/eluser]
Routing isnt my head problem, i think it will be $route['product/:num'] = "product/show_product/id"; . Buti cant find error in my controller/view/model. Help please, i doing thit 2. day by manual
#4

[eluser]aquary[/eluser]
Read the userguide, and more PHP basic again. You are doing everthing wrong & uncompleted. With this kind of code, it wouldn't work even on native PHP. I'm not even sure how could you run it without a parse error.




Theme © iAndrew 2016 - Forum software by © MyBB