Easy Question - Comments_View and Showing Article - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Easy Question - Comments_View and Showing Article (/showthread.php?tid=7718) Pages:
1
2
|
Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]Kesey[/eluser] I'm a beginner w/ PHP and CI. I've followed the blog tutorial and I'm trying to get the entry that one is commenting on to show up at the top of the comments page. I can get all of the entries to show up, similar to how it works on the main blog page, but how can I get just the one entry instead of using the loop to pull them all? Controller: Code: function comments() View: Code: <!--Get Article--> Thanks! Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]louis w[/eluser] Just add a limit to your get. This will limit the number of rows returned. Code: $data['query'] = $this->db->get('entries', 1); Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]gtech[/eluser] Controller: Code: function comments() View: Code: <h3><?=$query[0]['title']?></h3> there are many other ways to do the same thing though. Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]Kesey[/eluser] louis, gtech - thanks for the responses. I tried both of your suggestions and both of these solutions only display the first entry regardless of which entry the comments belong to. Is there a way to pass they entry_id so that the entry corresponding to the comments is displayed? Thanks. Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]Pascal Kriete[/eluser] You can add the id to the end of your url: example.com/blog/comments/10 And it will then be passed into your controller function as an argument. Code: function comments($id) Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]gtech[/eluser] Code: function comments($entryid) View: Code: <h3><?=$query[0]['title']?></h3> your url would pass in the entryid... <siteurl>/index.php/<controller>/comments/<entry_id> Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]gtech[/eluser] inparos solution is better as if you use row array it only returns 1 row. in the view you would access it by Code: <h3><?=$query['title']?></h3> Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]Kesey[/eluser] inparo - what would the view look like for that? I have: Code: <h3><?=$query[0]['title']?></h3> I've tried: Code: <h3><?=$query['id']['title']?></h3> The latter returns the Post Id, now to get the title that corresponds to that post id? Thanks. Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]gtech[/eluser] kessey - I already answered the question I think. <h3><?=$query['title']?></h3> result_array can return more than one row if the table allows duplicate entries so you need $query[<number>]['title'] row_array only returns one entry.. if there is a duplicate entry it will return the last one returned so you only need $query['title'] to access the data. Easy Question - Comments_View and Showing Article - El Forum - 04-20-2008 [eluser]Kesey[/eluser] I got it, but I'm sure there's a better way to get the text on the same line? Code: <h3><?=$query['id']?> <?=$query['title']?> <?=$query['body']?></h3> |