Welcome Guest, Not a member yet? Register   Sign In
A query in multiple tables
#1

[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 withSmile
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>&lt;?=getUserName()?&gt;'s wines</b></h1>

&lt;?php foreach($query->result() as $row): ?&gt;
<h3> &lt;?=$row->wine_id?&gt; </h3>
<p> &lt;?=$row->rating?&gt; </p>
<hr>
&lt;?php endforeach; ?&gt;

&lt;/body&gt;
&lt;/html&gt;

I'm starting with CI and PHP, please be patient.


Messages In This Thread
A query in multiple tables - by El Forum - 10-01-2008, 02:33 PM
A query in multiple tables - by El Forum - 10-01-2008, 04:33 PM
A query in multiple tables - by El Forum - 10-01-2008, 05:17 PM
A query in multiple tables - by El Forum - 10-01-2008, 05:38 PM
A query in multiple tables - by El Forum - 10-01-2008, 05:52 PM
A query in multiple tables - by El Forum - 10-01-2008, 08:42 PM
A query in multiple tables - by El Forum - 10-01-2008, 08:58 PM
A query in multiple tables - by El Forum - 10-01-2008, 09:16 PM



Theme © iAndrew 2016 - Forum software by © MyBB