Welcome Guest, Not a member yet? Register   Sign In
Table data presentation in template/view
#1

[eluser]Monotoba[/eluser]
Hello,

I'm brand new to code igniter and I am wondering if someone here can provide a demo of using nested loops for data presentation using the template system in ci. Here's a template to show you what I mean. How would I get the template engine to display data in a multidementional array containing multiple color rows containing multiple color cells?

Thanks for the help


<html>
<head>
&lt;title&gt;Color Table Demo</table>
&lt;/head&gt;

&lt;body&gt;

<table>

{color_row}
<tr>

{color_cell}
<td width="15" bgcolor="#{color}"> <font color="#{font_color}> {color} </font> </td>
{/color_cell}

</tr>
{/color_row}

</table>

&lt;/body&gt;

&lt;/html&gt;
#2

[eluser]John_Betong[/eluser]
Hi Monotoba,

Is this what you mean: http://johns-jokes.com/main/debug
&nbsp;
Code:
//==================================================
    function debug() { // default for controller without parameters
      // & remove dodgy html characters
    $this->load->helper('text'); // ascii_to_entities(...)
    $data =array();

    // get data from jokes table    
    $sql = 'select * from jokes where id<=64 order by id';
    $query  = $this->db->query($sql);

    // set htmltitle variables used in _doctype.php
    $data['htmltitle'] = 'Coloured Boxes';
    
    // view/display page
    $tmp = $this->load->view('_doctype.php', $data, true);
    echo $tmp;
    
    echo '&lt;body&gt;';
    echo '<h1>' .$data['htmltitle'] .'</h1>';
    echo "<div style='position:relative; width:1000px; margin:0 auto; text-align:left'>";        
    
     $ijoke = 1;
     foreach ($query->result() as $row):
       $bkk = 'rgb(' .rand(128,256) .',' .rand(128,256) .',' .rand(128,256) .')';
       echo "<p style='float:left; width:180px; height:300px; background:$bkk; padding:0 0.6em; border:outset 8px'>";
         $title = "<span style='font-size:1.2em; color: #f00'>" .nl2br($row->title) .'</span>';
         echo anchor('joke/show/' .$ijoke++, $title );
         $joke = substr($row->memo, 0, 142);  // limit characters
         $joke = nl2br($joke);
         echo br(2) .$joke;
          echo '</p>';
     endforeach;
    echo '</div>';
    echo '&lt;/body&gt;&lt;/html&gt;';  
    }
#3

[eluser]Monotoba[/eluser]
Hi John,

This is not quite what I was looking for however, I figured it out. What I wanted was a method to pass arrays of arrays, of arrays of values and have the template parser process them in a loops. My issue turned out to be that I was resetting one of the arrays of an array of values in the wrong place. Thus erasing a whole sector of my values.

Thanks for the help though :-)




Theme © iAndrew 2016 - Forum software by © MyBB