[eluser]earlyriser[/eluser]
I have 3 tables
WINES: id, name, year.
WINE_COMMENTS: id, user_id, wine_id, rating.
USER: id, name.
I would like to have a view with the next information
------------------------------------
This is user.name page
(list with
wines.name
wine_comments.rating
-------------------------------------
But I don't know how to make a query for this, because the query needs to know:
1. Who is the logged user to load only his wines
2. Relate in some way the wines_comments.wine_id with the wine.id
My current code shows the user's wines ratings, but it shows the wine id only and not the name because I don't know how to make the query.
Code:
//CONTROLLER
function comments()
{
$data['title']= "Comment Title";
$this->db->where('user_id', getUserProperty('id'));
$data['query']= $this->db->get('wine_comments');
$this->load->view('wine_comment.php', $data);
}
Code:
//VIEW
<head>
<title> <?=$title; ?> </title>
</head>
<body>
<h1><b><?=getUserName()?>'s wines</b></h1>
<?php foreach($query->result() as $row): ?>
<h3> <?=$row->wine_id?> </h3>
<p> <?=$row->rating?> </p>
<hr>
<?php endforeach; ?>
</body>
</html>
I'm starting with CI and PHP, please be patient.