0
Good afternoon, folks, I’d like to ask for your help on something I’ve been racking my brain about and I can’t seem to get it right
have 4 tables
- products ->id | Slug | title | info1 | info2 | info3
- prodnutri -> idNutricion | idProducto | porcion | info2 | info3
- prodpreparao -> idPreparo | idProducto | info1 | info2 | info3
- prodingredientes -> idIngredientes | idProducto | info1 | info2 |info3
the tables will have enough information and did not want to leave all in one.. so I believe it is better to do in dividing the information to 4.
I’m trying to do in Model the query and I’m missing, I’ve tried several ways and I can’t..
I can list the products and call everything straight, this way domain.com/products/see/product name
NA MODEL / Productmodel -- my basic query where I can bring all table product data
public function find($slug){ //
$this->db->where('slug', $slug);
return $this->db->get('productos')->row();
}
but when you do the Inner -- with a table, you need it to be with the 3 + tb product, I cannot and error.
public function find($slug){ //
$this->db->where('slug', $slug);
$this->db->select("productos.slug");
$this->db->from('productos');
$this->db->join('prodnutri', 'prodnutri.idNutricion = productos.slug');
$query = $this->db->get();
return $this->db->get('productos')->row();
}
NO CONTROLLER / products
public function ver($slug)
{
$this->load->view('incluir/cabecalho');
$data['producto'] = $this->ProductModel->find($slug);
$this->load->view('productos/producto', $data);
$this->load->view('incluir/rodape');
}
The problem is that I am not able to do the query in the model (I believe the controller is right! because all the data of the product tabla it brings right, but when I want to bring the data of the other Ablas it is giving error..
PHP Error was encountered Severity: Notice Message: Undefined Property: stdClass::$porcion
in view to using the vector like this
<?Php echo $producto->titulo;?> -- titulo da tb Productos
<?Php echo $producto->porcion;?> -- titulo da tb prodnutri
Can anyone help, I will be very grateful in a light to resolve the table with Inner Join..
tries to give a
var_dump($data['producto']);
after the$data['producto']
in your controller, that you see exactly what is returning.– Luiz