Welcome Guest, Not a member yet? Register   Sign In
Simple Question: Expanding on the Blog Tutorial
#4

[eluser]MT206[/eluser]
I have still not been able to get this to display the proper count. I might be misunderstanding what was shown in the above post but I do not think so.
From the code examples given above I do not understand why I would be changing the 'query' to 'comments' as that seems arbitrary and when I do I get the error: undefined variable comments which makes sense since there is no 'comments' variable in the index function to pass to the view. For more information the comment view looks like this:

Code:
<html>
    <head>
        <title><?php echo $title; ?></title>
    </head>
    <body>
        <h1>&lt;?php echo $heading; ?&gt;</h1>
        
        &lt;?php if ($query->num_rows() > 0): ?&gt;
            &lt;?php foreach($query->result() as $row): ?&gt;
                <p>&lt;?php echo $row->author; ?&gt;</p>
                <p>&lt;?php echo $row->body; ?&gt;</p>            
                <hr>
            &lt;?php endforeach; ?&gt;
        &lt;?php endif; ?&gt;
        
        &lt;?php echo form_open('blog/comment_insert'); ?&gt;
        &lt;?php echo form_hidden('entry_id', $this->uri->segment(3)); ?&gt;
            Comment:
            <p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
            Author:
            <p>&lt;input type="text" name="author" /&gt;&lt;/p>
            <p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>
        &lt;/form&gt;
        
        <p>&lt;?php echo anchor('blog', 'Back to Blog'); ?&gt;</p>
    &lt;/body&gt;
&lt;/html&gt;

And the Database setup is:

entries
id, title, body
comments
id, entry_id, author, body


Would I need another table that contains both entry_id and comment_id? I do not see how I could use data from both tables without manually writing an SQL query involving a JOIN or actually having a column for comment count which seems clunky.


Messages In This Thread
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 05:56 AM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 06:43 AM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 03:59 PM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-14-2010, 01:59 PM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-15-2010, 04:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB