ShoeLace1291 Posted September 7, 2010 Share Posted September 7, 2010 I'm using the template parser class in codeigniter to display database results in a view file. Is it possible to parse an array like this: foreach($query->result() as $news){ $articles[$news->id] = array( 'ID' => $news->id, 'TITLE' => $news->title, 'BODY' => $news->body ); } $data = array( 'NEWS_ARTICLES' => array( $artcicles ); $this->parser->parse('index.tpl', $data); <div id='news'> <h1>Recent News</h1. {NEWS_ARTICLES} <div class='article'> <h1>{TITLE}</h1> <p>{BODY</p> </div> {/NEWS_ARTICLES} </div> Quote Link to comment https://forums.phpfreaks.com/topic/212809-iterating-variable-pairs-in-codeigniter/ Share on other sites More sharing options...
keevitaja Posted September 9, 2010 Share Posted September 9, 2010 i have never used templated before, but: $query->result() should allready give you the result as array, so no need to walk it trought! whatabout just $data['articles'] = $query->result(); $this->parser->parse('index.tpl', $data); and in template file {articles} so some stuff with values like {title} and {body} {/articles} Quote Link to comment https://forums.phpfreaks.com/topic/212809-iterating-variable-pairs-in-codeigniter/#findComment-1109153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.