Welcome Guest, Not a member yet? Register   Sign In
Template parser class with database array
#1

[eluser]alfisahr[/eluser]
Dear all,

please help me. i'm confused about this problem.

i have records on my table. Let say guestbook

id sender
1 Alfin
2 John
3 Merry

This is My template.php

<html>
.....
<body>
{content}
....
<html>

If i will call all the records with database array on my variable template, i have try this :

....
function index() {
$query = $this->db->query('select * from guestbook');
$row = $query->row_array();
$data = array('content' => $row['sender']);
$this->parser->parse('template',$data);
................

But, the output just showing the last of record. Here this

Merry

I want to show all records, hw about the code. please help me...

rgrds
Alfisahr
#2

[eluser]alfisahr[/eluser]
any idea for that ???

tq
alfisahr
#3

[eluser]victorche[/eluser]
Try this:
Code:
function index() {
      $query = $this->db->query(SELECT * FROM guestbook);
      foreach ($query->result_array() as $row)
      {
           $senders[] = array(
             'sender' => $row['sender'],
            );
      }
      $data = array('content' => $senders);
      $this->parser->parse('template', $data);
}
And then in your template:
Code:
<html>
<body>
      <ul>
      {content}
            <li>{sender}</li>
      {/content}
      </ul>
&lt;/body&gt;
&lt;/html&gt;
As far as I know, if you have repeating blocks in your template, you should use {repeating_content} .... {/repeating_content}
#4

[eluser]alfisahr[/eluser]
Thank u so much victorche, its running well.

I need that for showing several news in database.

tq so much
#5

[eluser]Unknown[/eluser]
hi,every one..
I m new to the codeigniter.
Now i m developing the newsletter module.
After parsing the data,how can i send that newsletter to the particular user?
Will i may follow the normal $this->email->send(); method?
Please guide me....





Thank u....




Theme © iAndrew 2016 - Forum software by © MyBB