EllisLab text mark
Advanced Search
     
Table data presentation in template/view
Posted: 06 September 2007 07:19 PM   [ Ignore ]
Joined: 2007-09-05
24 posts

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>
  <title>Color Table Demo</table>
</head>

<body>

  <table>

  {color_row}
  <tr>

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

  </tr>
  {/color_row}

  </table>

</body>

</html>

 Signature 

If you ask me if it can be done, the answer is yes! It can always be done. The correct question however, is what will it cost?

 
Posted: 06 September 2007 11:36 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-12-26
727 posts

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'$datatrue);
    echo 
$tmp;
    
    echo 
'<body>';
    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->memo0142);  // limit characters 
         
$joke nl2br($joke);
         echo 
br(2) .$joke;
          echo 
'</p>';
     endforeach; 
    echo 
'</div>';
    echo 
'</body></html>';  
    
 Signature 

Joke of the day - Bulletin Board Ideas     (ongoing development site)

My Hippy Trail    Source code   

Latest Project

 
Posted: 06 September 2007 11:44 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-09-05
24 posts

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 grin

 Signature 

If you ask me if it can be done, the answer is yes! It can always be done. The correct question however, is what will it cost?