Welcome Guest, Not a member yet? Register   Sign In
having problem with templates
#1

[eluser]gayathri[/eluser]
Hi all,

I am newly leaning about templates, beginning itself i am stacking a lot, if i list static variable, templates is working , but if i try to fetch the table from the database, it not list the values, actually i don;t know the right way to do,so please let me know.
my coding is

in controller

Quote:function blog_template()
{
$query = $this->db->query("SELECT * FROM users");
$data = array(
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading',
'blog_entries' => $query->result_array()
);

$this->parser->parse('blog_template', $data);

}


Users table containg name and place, so how i will display these values in views
#2

[eluser]Michael Wales[/eluser]
Code:
<?= print_r($blog_entries); ?>

Do that in your view - it will tell you what your vars are, then echo them like:
Code:
<?= $blog_entries['myvar']; ?>

Note: the variables are the same name as your columns in the users table.
#3

[eluser]gayathri[/eluser]
Hi ,

Thanks for your reply, i tried this one, if i print_r , it lists the items in array, but <?= $blog_entries['myvar']; ?> this is not working, actaully i did like this

<?= $blog_entries['name']; ?>
<?= $blog_entries['place']; ?>

but not working, is that right?
#4

[eluser]Rick Jolly[/eluser]
Code:
<?php foreach($blog_entries as $row) : ?>
<?= $row['name']; ?>
<?= $row['place']; ?>
<?php endforeach; ?>

If you want to use the template parser syntax, the user guide is pretty clear:
Code:
{blog_entries}
{name}
{place}
{/blog_entries}
#5

[eluser]gayathri[/eluser]
Hi Jolly,

Its working now, but i have a doubt, if you use php tags like this, then what is the use of templates? , i have go through the user guide also(sorry i don't have much knowledge in this), but i don;t know smartly that's y i am struggling now. but i heard , within the template itself we have the for loop options instead of php tags, is it there like this?, sorry to asking this chilly question, but i want to know about the templates. Thanks Smile
#6

[eluser]gayathri[/eluser]
Hi,

Sorry for the wrong reply, now its working nice, thank you very much jolly, actually i didn't notice your last line, that's y i confused, is there any site , to learn basic command about how to use templates in all way, In CI i saw only small examples only.




Theme © iAndrew 2016 - Forum software by © MyBB