Welcome Guest, Not a member yet? Register   Sign In
[Resolved] SQL Question on CI Active Record Class Usage
#1

[eluser]Nano HE[/eluser]
I am using CodeIgniter Active Record Class to generat tables, my code snippet below.

I try to generated TWO tables that by different years: 2011 and 2010.


Code:
/////////////////// YEAR 2010 ////////////////
// It works quite well to generate table - 2010                
$this->db->select('year, distance, gender, rank, name, chiptime, racenumber');                  
$this->db->order_by("year", "desc");                  
$this->db->order_by("distance, gender, rank", "asc");                  
$topNum = 5;                
$year = 2010;                
$this->db->where('rank <=', $topNum);                
$this->db->where('year', $year);                    
$this->load->model('eventmain_model');                  
$data['results_2010'] = $this->eventmain_model->get_result_top5($city);      
$tmpl =  $this->common_model->html_table_config();        
$this->load->library('table');                
$this->table->set_template($tmpl);                
$this->table->set_heading(array('Year', 'Dis', 'gender','Rank', 'Name', 'ChipTime', 'RaceNo'));


/////////////////// YEAR 2011 ////////////////
// It doesn't work well, since it always included 2010 and 2011 data to my 2nd 2011 new table.  
// I want to remove 2010 rows from the 2011 table. How can I fix this?
// Is ther an method to new the db select object and generate my 2011 table?       //Thanks.                                    
// load database class                  
$this->db->select('year, distance, gender, rank, name, chiptime, racenumber');                  
$this->db->order_by("year", "desc");                  
$this->db->order_by("distance, gender, rank", "asc");                  
$topNum = 5;                
$year = 2011;                
$this->db->where('rank <=', $topNum);                
$this->db->where('year', $year);                    
$this->load->model('eventmain_model');                  
$data['results_2011'] = $this->eventmain_model->get_result_top5($city);      
$tmpl =  $this->common_model->html_table_config();        
$this->load->library('table');                
$this->table->set_template($tmpl);                
$this->table->set_heading(array('Year', 'Dis', 'gender','Rank', 'Name', 'ChipTime', 'RaceNo'));

http://codepad.org/jYADJxlZ

Appreciated for you comments and replies.
#2

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...table.html

Quote:$this->table->clear()

Lets you clear the table heading and row data. If you need to show multiple tables with different data you should to call this function after each table has been generated to empty the previous table information.
#3

[eluser]Nano HE[/eluser]
@noctrum, thanks a lot. I fixed my issue by add the code below to my View page.

Code:
echo 'Table_2010<br>';

$this->table->set_heading(array('Year', 'Dis', 'gender','Rank', 'Name', 'ChipTime', 'RaceNo'));

echo $this->table->generate($results_2010);
$this->table->clear();

echo '<br>';
echo 'Table_2011<br>';
$this->table->set_heading(array('Year', 'Dis', 'gender','Rank', 'Name', 'Lap', 'RaceNo'));
echo $this->table->generate($results_2011);




Theme © iAndrew 2016 - Forum software by © MyBB