从html表中的数据库每天显示多个appointement

时间:2016-03-23 10:42:17

标签: arrays codeigniter multidimensional-array

我使用Codeigniter 3和bootstrap 3,我在数据库中有一个表RDV(Doctor Appointment)我想在数据库的视图中显示医生预约。 我希望输出看起来像这样:

----------------------------------------------------------------------------
|DATE               | TIME               | EVENT         | PATIENT        |
----------------------------------------------------------------------------
|2016-06-13         | 03:28              |Consultation   |IHAB BARI       |
----------------------------------------------------------------------------
|                   | 05:00              |Viste          |ISSHAK KOMA     |
----------------------------------------------------------------------------
|                   | 06:15              |Esthetique     |ABASS DOSSO     |
----------------------------------------------------------------------------
|2016-07-17         | 08:10              |Visite         |KOKO TASSI      |
----------------------------------------------------------------------------

数据库中的表:ID |日期| HEURE_RDV | MOTIF_RDV |患者| DETAIL_RDV

在模型中我有这个代码:

public function rdv_selectAll_mdl()
{

    $query = $this->db->get('rdv');
    return $query;
}
控制器中的

public function rdv_selectAll()
{

    $this->load->model('calender_model');

    $query = $this->calender_model->rdv_selectAll_mdl();
    $data = array();
    foreach ($query->result() as $row) {
        $data[$row->dateRdv][] = $row->heureRdv;
        $data[$row->dateRdv][] = $row->patientRdv;
        $data[$row->dateRdv][] = $row->motifRdv;
        $data[$row->dateRdv][] = $row->detailRdv;
    }

    $this->load->view('gs_calender');

}

使用此控制器我试图将时间和事件以及患者和细节放在一个日期我不确定它是否正确,我想一个multidimentionnel数组将多行放在一行并在html中使用rowspan表,如果正确的话可以循环查看任何一个可以帮我解决的问题。

1 个答案:

答案 0 :(得分:0)

你为什么不这样做:

$data['rdv'] = $query->result_array(); 
$this->load->view('gs_calender',$data);

然后在视图内

foreach($rdv as $r){
//echo your columns for every row 
}

或者如果你想让它更好,你可以使用表库,在这里查看:

  

https://ellislab.com/codeigniter/user-guide/libraries/table.html

使用表库,您可以执行以下操作:

$this->load->library('table');

//add bootstrap class to table 
$tmpl = array ( 'table_open'  => '<table class="table">' );
$this->table->set_template($tmpl);

//get your table
$data['rdv'] = $query->result_array();

//add table th
$this->table->set_heading('Date','Time','Event','Patient');

//loop inside of results
foreach($data['rdv'] as $t){
            $this->table->add_row($t['date'],$t['time'],$t['event'],$t['patient']);
        }

//generate table and pass it to view
$data['table'] = $this->table->generate();
$this->load->view('gs_calender',$data);

然后在视图内部做

echo $table;

在评论中编辑问题:

$daterd="";
    //loop inside of results
    foreach($data['rdv'] as $t){

  if($daterd == $t['dateRdv']){  
       $t['dateRdv'] = "";
                } 
  else {$daterd = $t['dateRdv'];}

$this->table->add_row($t['dateRdv'],$t['heureRdv'],$t['patient_id'],$t['detailRdv']);
                    $t['dateRdv']="";


            }