Welcome Guest, Not a member yet? Register   Sign In
display data in colums
#1

[eluser]Unknown[/eluser]
In html I found out how to display my database in 4 columns using a while loop :

id[1] id[2] id[3] id[4]
name[1] name[2] name[3] name[4]

id[5] ............
name[5]...........

In codeigniter I know how to use foreach($query->result() as $row) but I haven't been able to display in columns. I have tried many methods but none of them work. I've tried with <div> and tables.

thank you.
#2

[eluser]John_Betong_002[/eluser]
Here is one of many methods for you to try:

http://ellislab.com/codeigniter/user-gui...table.html

Before I forget, please learn how to use code tags when posting. It really helps others to understand the script and prevents some posters from getting annoyed.

Oh and welcome to CI Smile
&nbsp;
&nbsp;
#3

[eluser]Unknown[/eluser]
Thank you John_Betong_002. But how can I turn "$data['query']=$this->db->get('mytable');" into a one-dimensional array so I can apply $this->table->make_columns().
#4

[eluser]John_Betong_002[/eluser]
Try this:

Code:
$this->load->library('table');
  
  $sql    = 'SELECT id, title FROM your_table_name LIMIT 0,3';
  $query  = $this->db->query($sql);
  
  $data   = array();
  $data[] = array('id', 'title');
  foreach($query->result_array() as $row):
    $data[] = $row;
  endforeach;            

  $tmpl = array
  (
    'table_open'          => '<table style="border:double 4px #333;width:20em;text-align:center">',

    'heading_row_start'   => '<tr style="width:10em;color: red">',
    'heading_row_end'     => '</tr>',
    'heading_cell_start'  => '<th style="width:10em;color: cyan">',
    'heading_cell_end'    => '</th>',

    'row_start'           => '<tr style="width:10em;color:yellow">',
    'row_end'             => '</tr>',
    
    'cell_start'          => '<td style="width:10em;color:green">',
    'cell_end'            => '</td>',

    'row_alt_start'       => '<tr style="width:10em;color:blue">',
    'row_alt_end'         => '</tr>',
    
    'cell_alt_start'      => '<td style="width:10em;color:orange">',
    'cell_alt_end'        => '</td>',

    'table_close'         => '</table>'
  );
  
  $this->table->set_template($tmpl);
  echo $this->table->generate($data);
  die(QW);
&nbsp;
&nbsp;
I forgot to mention - Welcome to the forum...

...and to prevent some posters getting upset

1. please post in the correct forum

2. please learn how to enclose your code inside the code tags Smile
&nbsp;
&nbsp;
#5

[eluser]John_Betong_002[/eluser]
Hi dvinatea,

Thanks for the jpg showing what you require.

I had some time on my hands so created the following


demo


source
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB