Welcome Guest, Not a member yet? Register   Sign In
display mysql_result in table with modifications
#1

[eluser]mandril[/eluser]
Hi !

I want to display some data from a query in a table, im using the CI library and works great, but i want to add some modifications to the table im showing.. i want to add a new column with a link or.. add a link to the Id.

This is my code of the view:

Code:
<p>Usuarios:</p>
&lt;?php $this->table->set_heading('ID', 'Usuario', 'Clave', 'Email');
$tmpl = array ( 'table_open'  => '<table border="0" cellpadding="2" cellspacing="1">' );
$this->table->set_template($tmpl);

  foreach($results->result() as $dato):
    $array[0] = anchor('usuario/form/'.$dato->id, 'id');
    $array[1] = $dato->usuario;
    $array[2] = $dato->clave;
    $array[3] = $dato->email;  
  endforeach;
  
  echo $this->table->generate($array);

echo $this->pagination->create_links(); ?&gt;

Ok i know the problem, but don't know how to solve it.. the $results is the CI_mysql_result Object and i can generate a table from it using:

Code:
$this->table->generate($results);

But i want to add that modification and so use the generation from array, but without losing pagination. So with a foreach i can get the information and create the link in the id. but when i generate the table it only generates the first, this is because im always replacing my arrays position with other values.

Can someone help me with this ?
#2

[eluser]GSV Sleeper Service[/eluser]
Code:
foreach($results->result() as $dato):
    $array[0] = anchor('usuario/form/'.$dato->id, 'id');
    $array[1] = $dato->usuario;
    $array[2] = $dato->clave;
    $array[3] = $dato->email;  
    $this->table->add_row($array);
endforeach;

echo $this->table->generate();
#3

[eluser]mandril[/eluser]
i solve it using the classic way. but i would love to know how to do it using the table generation of CI.

here is the code:

Code:
<p>Usuarios:</p>

<table cellpadding="2" cellspacing="1" border="1">
&lt;?php

  foreach($results->result() as $dato):
  echo "
    <tr>
        <td>".anchor('usuario/form/'.$dato->id, 'id')."</td>
        <td>$dato->usuario;</td>
        <td>$dato->clave;</td>
        <td>$dato->email;</td>
    </tr>
    ";
  endforeach;
  
echo "
</table>";

echo $this->pagination->create_links(); ?&gt;


anyone please ?
#4

[eluser]mandril[/eluser]
[quote author="GSV Sleeper Service" date="1232655725"]
Code:
foreach($results->result() as $dato):
    $array[0] = anchor('usuario/form/'.$dato->id, 'id');
    $array[1] = $dato->usuario;
    $array[2] = $dato->clave;
    $array[3] = $dato->email;  
    $this->table->add_row($array);
endforeach;

echo $this->table->generate();
[/quote]

ooh thnx! that is what I was looking for =D




Theme © iAndrew 2016 - Forum software by © MyBB