Accessing database value in view |
[eluser]patsm[/eluser]
I'm new to Code Igniter and I've read all through the TOC and even have an existing application to use as a guide. However, I don't understand how to access a value from the database in one of my views. This is part of my controller Code: class classifieds extends Controller { This is the getFeatures function in the mdl_common Model as referenced in the Controller Code: function getFeatures() { The table I am accessing in my mySQL database is called features. I have two fields in that table called leftTopNav and leftBotNav. I would like to access the value of leftTopNav in my view in the file 'view.sidebar.php' (this is referenced in my controller and displays but I don't understand how to get the values. I've tried $features['leftTopNav'], I've tried $features[0], I've tried $leftTopNav along with all sorts of other things. I just don't get it!!! I know this is such a simple thing, but it has me stuck. Can someone tell me how to access this data in the form of a variable? Thanks!
[eluser]GSV Sleeper Service[/eluser]
$query->row() returns an object. you access this in your view by using $features->leftTopNav if you prefer the square bracket (array) notation, then use $query->row_array()
[eluser]patsm[/eluser]
That worked, thanks so much!!!! However, is there a better way to do this or am I doing it correctly?
[eluser]Sumon[/eluser]
If you are using PHP 5 then the most powerful and useful one is using Method Chaining. Use this as common syntax for all of your queries in model. Code: $query = $this->db->select('title') |
Welcome Guest, Not a member yet? Register Sign In |