Part of the EllisLab Network
   
 
display mysql_result in table with modifications
Posted: 21 January 2009 11:57 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  31
Joined  01-21-2009

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:

<p>Usuarios:</p>
<?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(); ?>

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:

$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 ?

Profile
 
 
Posted: 22 January 2009 09:22 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  528
Joined  03-13-2008
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();
 Signature 

:wq

Profile
 
 
Posted: 22 January 2009 09:47 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  31
Joined  01-21-2009

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:

<p>Usuarios:</p>

<
table cellpadding="2" cellspacing="1" border="1">
<?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(); ?>


anyone please ?

Profile
 
 
Posted: 22 January 2009 09:50 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  31
Joined  01-21-2009
GSV Sleeper Service - 22 January 2009 09:22 AM
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();

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

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120296 Total Logged-in Users: 49
Total Topics: 126414 Total Anonymous Users: 5
Total Replies: 664813 Total Guests: 451
Total Posts: 791227    
Members ( View Memberlist )