• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Table data presentation in template/view


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

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




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





Hi Monotoba,

Is this what you mean: http://johns-jokes.com/main/debug
    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>';
    echo '</div>';
    echo '&lt;/body&gt;&lt;/html&gt;';  

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 :-)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.