Welcome Guest, Not a member yet? Register   Sign In
Can't figure out how to write this query properly... involves two tables.
#1

[eluser]dallen33[/eluser]
Code:
<h1>Latest Unread Comments</h1>
    &lt;?php
        $ads_query = $this->db->get_where('ads', array('artist' => $this->dx_auth->get_user_id()));
        $ads_row = $ads_query->row_array();
        
        $comments_query = $this->db->get_where('comments', array('ad_id' => $ads_row['id']));
        
        if ($comments_query->num_rows() > 0):
        foreach($comments_query->result_array() as $comments_row):
    ?&gt;
    &lt;?php echo $comments_row['id'] ?&gt;
    &lt;?php
        endforeach;
        elseif ($comments_query->num_rows() == 0):
    ?&gt;
    Sorry, nothing found.
    &lt;? endif; ?&gt;

Basically, I want to select all rows from table 'ads' where field 'artist' equals to the user_id (in this case, 3). Then, I want to select all rows from table 'comments' where field 'ad_id' equals to any 'id' from the table 'ads' that was previously selected.

I can't seem to figure out. I keep getting my elseif statement ("Sorry, nothing found."). There is only one row in the comments table, and the ad_id equals to a row id in 'ads'.


Messages In This Thread
Can't figure out how to write this query properly... involves two tables. - by El Forum - 01-13-2009, 04:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB