2017-04-08 5 views
1

誰かが私を助けてください、私はmvp手順でCodeIgniterを使用します。私はこのようなテーブルビューにデータを表示したい場合は表は、codeigniterのデータ行に1列のデータを表示しますか?

enter image description here

ことが可能である:私はこのようなデータベースを持っていますか?

enter image description here

すべてが動作していないid_status別の日付でデータを取得するとき私は、日にお見せすることができます。

コントローラの場合は1つの日付のみ。

public function status() 
{ 
    $tanggal1 = '2017-03-28'; 
    $data['status'] = $this->M_Reports->status($tanggal1); 
    $this->load->view('homepage/template'); 
    $this->load->view('report/status', $data); 
} 

モデル:

public function status($tanggal1) { 
     $sql = "SELECT operasional.id_ops, operasional.id_status, operasional.tanggal, peralatan.nm_peralatan FROM operasional INNER JOIN peralatan ON operasional.id_peralatan = peralatan.id_peralatan WHERE tanggal='$tanggal1' ORDER BY id_ops"; 
     return $this->db->query($sql)->result(); 
} 

とビュー:

<?php 
    $start = 0; 
    foreach($status as $data) { 
?> 
    <tr> 
    <td><?php echo ++$start ?> </td> 
    <td><?php echo $data->nm_peralatan ?></td> 
    <td><?php echo $data->id_status ?></td> 
    <td><?php echo $data->tanggal ?></td> 
    </tr> 
<?php 
    } 
?> 
+0

なぜあなたのビューはデータベースから取得したものに基づいていますか? dbテーブルから必要なインデックスを取得するクエリを作成するだけです。 –

+0

は、ビュー内の日付が静的または動的ですか? –

+0

@georoot異なる日付のときにid_statusをループする必要があるときに混乱しました。助けて – khoirul

答えて

0

あなたのモデル関数を使用すると、上部のみを送信する必要があなたのコントローラから今この

public function status($top_of_date) 
{ 
    // This will get all dates 
    $dates=$this->db->distinct()->select('tanggal')->from('operasional')->get()->result_array(); 
    // This will get all patients/peralatan 
    $patients=$this->db->distinct()->select('id_peralatan')->from('operasional')->get()->result_array(); 
    // Loop through peralatan 
    for($i=0;$i<count($patients);$i++) 
    { 
     $st=$this->select('id_peralatan')->from('operasional')->WHERE('id_peralatan',$patients[$i])->get()->result_array(); 
     // Start Creating an array for this index 
     $data[$i]=array(
      'id_peralatan'=>$st[0] 
     ); 
     // loop through dates 
     for($j=0;$j<count($dates);$j++) 
     { 
      //if date is greater than top of date 
      if($dates[$i]>$top_of_date) 
      { 
       $st=$this->db->select('id_status')->from('operasional')->WHERE('tanggal',$dates[$i])->get()->result_array(); 
       // Create index and save the status 
       $data[$i]['top_of_date']=$st[0]['id_status']; 
      } 
      elseif($dates[$i]<$top_of_date) 
      { 
       $st=$this->db->select('id_status')->from('operasional')->WHERE('tanggal',$dates[$i])->get()->result_array(); 
       // Create index and save the status 
       $data[$i][$dates[$i]]=$st[0]['id_status']; 
      } 
     } 
    } 
    return $data; 
} 

ようにする必要があります日付の。好き。

public function status() 
{ 
    $tanggal_top = '2017-03-28'; 
    $data['status'] = $this->M_Reports->status($tanggal_top); 
    $this->load->view('homepage/template'); 
    $this->load->view('report/status', $data); 
} 
+0

ありがとうございます。 @マリク、私はこれを試します;) – khoirul

+0

親愛なるmr。 @Malik Mudassar、私は$ st = $ this-> db-> select( 'id_peralatan') - > from( 'operasional') - > WHERE( 'id_peralatan'、$ patients [$ i])という行にエラーがありました。 > get() - > result_array();なぜなら、$ patienstsはまだ配列なので、このようなエラーは、長時間の議論が必要な場合は、SELECT 'id_peralatan'から' operasional' WHERE 'id_peralatan' =' Array' – khoirul

+0

です。私と一緒にチャットhttp://chat.stackoverflow.com/rooms/11/phpに参加してください –

関連する問題