开发者

SQL Question on CI Active Record Class Usage

I am using CodeIgniter Active Record Class to generat tables, my code snippet below.

I try to generated TWO tables from on DateBase table; and the two HTML tables named Table_2010 and Table_2011.

/////////////////// YEAR 2010 ////////////////
// It works quite well to generate 2010 result table.

$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;                   
                $array = array('rank <=' => $topNum, 'year' => $year);
                $this->db->where($array); 


                $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 ////////////////
// I need query several different fields from the same data base table.
// such as I query 'lap', otherwise 'chiptime'
// 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, lap, 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', 'Lap', 'RaceNo'));


Got the answer from CI official forum.

$this->table->clear();

And I fixed the issue by add the code to my View Page. Thanks.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜