1
Please help me, I’m a beginner.
Well, I’m with a website with codeigniter, it’s showing my recipes perfectly on:
<?php foreach ($receitas as $receita) :?>
Now I want to create a loop that only shows the recipes that are in the favorites, which in this case is another table.
I need it to recover all the logged-in user’s id_recipe, in case 35, and the above loop shows all of them, without showing the other unsaved ones.
more information if you need:
CONTROLLER
public function favoritos(){
$this->load->model("Receitas_model");
$lista = $this->Receitas_model->buscaTodos();
$dados = array ("receitas" => $lista);
$this->load->view('templates/header');
$this->load->view('receitas/favoritos', $dados);
$this->load->view('templates/footer');
}
MODEL
public function buscaTodos(){
$this->db->order_by('criado','desc');
return $this->db->get("receitas")->result_array();
}
The logged in user can have several recipes saved as favorite, and need to show only those saved, do not want to show all.
Welcome to @Gabriel Ichikawa Craice! Add your question more info about the other table
favoritos
, and also what you have tried to solve the problem. But in advance, with the information you have put, it seems that only you should add aINNER JOIN
in your consultation lynching your tablefavoritos
.– 8biT
Hello @8bit , first thank you for the reply. I put the format image of the bookmarked table, it contains only " ID (int) , id_usuario(int) , id_recipe(int) " it only stores the information of when a user adds a certain recipe to the bookmarks, obviously the same user can have several saved recipes, and need to show this, all recipes saved by user X.
– Gabriel Ichikawa Craice