Welcome Guest, Not a member yet? Register   Sign In
Calling the database from a view file?
#1

[eluser]timsby[/eluser]
I am adding some features to a new blog system i am building from scratch. I'm using it as an opportunity to learn more about MVC and Ci. I want to display how many comments a particular post has and the only way I have figured out is by calling a database record from the view file like such...

Code:
<?php
    $this->db->where('entry_id', $row->id);
    $comments_num = $this->db->count_all_results('comments');
?>

<p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments ('.$comments_num.')');?&gt;</p>

I've read my explanation of the MVC functionality and shouldn't i be using a model to handle this for me? If so how? I haven't been able to figure out an alternative method. Thank you in advance for any advice!


Messages In This Thread
Calling the database from a view file? - by El Forum - 02-08-2009, 11:42 AM
Calling the database from a view file? - by El Forum - 02-08-2009, 12:04 PM
Calling the database from a view file? - by El Forum - 02-08-2009, 01:18 PM
Calling the database from a view file? - by El Forum - 02-08-2009, 01:54 PM
Calling the database from a view file? - by El Forum - 02-08-2009, 02:16 PM
Calling the database from a view file? - by El Forum - 02-08-2009, 02:49 PM
Calling the database from a view file? - by El Forum - 02-08-2009, 02:54 PM
Calling the database from a view file? - by El Forum - 02-10-2009, 12:36 AM
Calling the database from a view file? - by El Forum - 02-11-2009, 08:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB