2017-11-23 7 views
0

私はエラーポップアップメッセージを表示しようとしていましたが、私はGoogleから多くの研究を行った後、すべてのチュートリアルは私には役に立たない。このプロジェクトでは、「rn」を使用して検索し、「RN、NAME、D.O.B、AGE、GENDER、RACE、RELIGION」を検索します。今私は 'rn'の検証を設定したいと思います。たとえば、 'rn'がデータベース内のデータと一致しない場合、エラーメッセージが表示されます。 (英語は私の母国語ではないので、私の英語が壊れて申し訳ありません)。
これはコントローラである:Codeigniterデータが一致しないエラーポップアップメッセージ

<?php $this->load->view('template/header');?> 

    <div class="container"> 
    <div class="panel panel-info"> 
      <div class="panel-body"> 
    <?php 
     echo form_open('index.php/patient/execute_search'); 

     echo form_input(array('name'=>'search')); 

     echo form_submit('search_submit','Submit'); 


    ?> 
     </div> 
     </div> 
    </div> 
    <?php $this->load->view(

'template/footer');?> 

これはsearch_results.phpするための図である:

<?php 

class Patient_model extends CI_Model { 

    public function get_results($search_term='default') 
    { 
     // Use the Active Record class for safer queries. 
     // $this->load->helper('share_function'); 
     $this->db->select('lifeline.pesakit.rn,lifeline.pesakit.nama,lifeline.pesakit.tarikhlahir,lifeline.jantina.nama as jantina,lifeline.agama.nama as agama,lifeline.bangsa.nama as bangsa'); 
     $this->db->from('lifeline.pesakit as pesakit'); 
     $this->db->join('lifeline.jantina','lifeline.jantina.kod = lifeline.pesakit.jantina'); 
     $this->db->join('lifeline.agama','lifeline.agama.kod = lifeline.pesakit.agama'); 
      $this->db->join('lifeline.bangsa','lifeline.bangsa.kod = lifeline.pesakit.bangsa'); 
     $this->db->where('rn',alphaToNumber($search_term)); 

     $query = $this->db->get(''); 

     // Return the results. 
     return $query->result_array(); 
    } 



} 

これはsearch_form.phpするための図である。

<?php 

class Patient extends CI_Controller { 

    public function __construct() 
    { 
     parent::__construct(); 

     $this->load->helper('form'); 

     $this->load->model('Patient_model'); 
    } 

    public function index() 
    { 
     $data['content'] = 'patient/search_form'; 
     $data['title']="SEARCH"; 
     $data['sub']='SEARCH PATIENT'; 
     $this->load->view("design/index",$data); 

    } 

    public function execute_search() 
    { 

     $search_term = $this->input->post('search'); 

     $data['results'] = $this->Patient_model->get_results($search_term); 

     $this->load->view('patient/search_results',$data); 

    } 


} 


これはモデルであります

<?php $this->load->view('template/header');?> 
<div class="container"> 
<div class="panel panel-info"> 
     <div class="panel-heading">Patient Demographic</div> 
     <div class="panel-body"> 
     <div class="form-group"> 
     <?php 
      $no=0; 
      foreach ($results as $row): 
      $no++; 
      ?> 
      <table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;"> 

      <tr align='left' > 
       <th>RN</th> <th> :</th> <th style="font-weight: normal;"><?php echo numberToAlpha($row['rn']);?></th> 
       <th>Name</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['nama'];?></th> 
       <th>Date.of.Birth</th> <th>:</th> <th style="font-weight: normal;"><?php echo dateFormat($row['tarikhlahir']);?></th> 
       <th></th><th></th><th></th> 
      </tr> 

      <tr align='left'> 
       <th>Age </th><th> :</th> <th style="font-weight: normal;"><?php echo calculateCurrentAge ($row['tarikhlahir']);?></th> 
       <th>Gender</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['jantina'];?></th> 
       <th>Race</th> <th>:</th> <th style="font-weight: normal;"><?php echo $row['bangsa'];?></th> 
       <th>Religion</th> <th> :</th> <th style="font-weight: normal;"><?php echo $row['agama'];?></th> 
      </tr> 

      <?php endforeach ?> 
      </table> 
     </div> 
    </div> 
</div> 
<?php $this->load->view('template/footer');?> 


私はcodeigniterのためにまったく新しく、私が学んだことはすべてmr.googleからだから、私の周りの誰も助けることができないので、みんな助けてください。ありがとうございました。

+0

'rn'はあなたのテーブルの列ですか? –

答えて

1

結果が見つからない場合、get_results()関数は空の配列を返し、foreachループは失敗します。

<?php $this->load->view('template/header');?> 
<div class="container"> 
    <div class="panel panel-info"> 
     <div class="panel-heading">Patient Demographic</div> 
     <div class="panel-body"> 
      <div class="form-group"> 
       <?php 
       if (count($results) > 0): 
       $no = 0; 
       foreach ($results as $row): 
       $no++; 
       ?> 
       <table align="center" length="200" border='0' cellpadding='5' cellspacing='6' style="font-family:arial;"> 

        <tr align='left'> 
         <th>RN</th> 
         <th> :</th> 
         <th style="font-weight: normal;"> 
          <?php echo numberToAlpha($row['rn']);?> 
         </th> 
         <th>Name</th> 
         <th>:</th> 
         <th style="font-weight: normal;"> 
          <?php echo $row['nama'];?> 
         </th> 
         <th>Date.of.Birth</th> 
         <th>:</th> 
         <th style="font-weight: normal;"> 
          <?php echo dateFormat($row['tarikhlahir']);?> 
         </th> 
         <th></th> 
         <th></th> 
         <th></th> 
        </tr> 

        <tr align='left'> 
         <th>Age </th> 
         <th> :</th> 
         <th style="font-weight: normal;"> 
          <?php echo calculateCurrentAge ($row['tarikhlahir']);?> 
         </th> 
         <th>Gender</th> 
         <th>:</th> 
         <th style="font-weight: normal;"> 
          <?php echo $row['jantina'];?> 
         </th> 
         <th>Race</th> 
         <th>:</th> 
         <th style="font-weight: normal;"> 
          <?php echo $row['bangsa'];?> 
         </th> 
         <th>Religion</th> 
         <th> :</th> 
         <th style="font-weight: normal;"> 
          <?php echo $row['agama'];?> 
         </th> 
        </tr> 
       </table> 
       <?php 
       endforeach; 
       else: 
       ?> 
       <p>No results found</p> 
       <?php endif; ?> 
      </div> 
     </div> 
    </div> 
    <?php $this->load->view('template/footer');?> 

注:このように、あなたがどんな結果を持っているかどうかを確認する必要があるという意味count($results) > 0かどうかを確認する必要があり、私は、foreachループ内</table>ブラケットを移動したり、テーブルを終了していません。なぜあなたがpatientごとに新しいテーブルを作成したいのか分かりませんが、誰が私を判断するのですか)。また、使用しない場合は、カウンタ($no)を起動する必要はありません。

+0

「結果が見つかりません」というメッセージをポップアップメッセージにしたい場合はどうすればよいですか? –

+0

AJAXとjqueryを使用する必要があり、すべてがあなたのために(そしてあなたの質問の範囲外に)少し複雑になります。あなたが本当にそれをしたいと思えば、私はそれを研究することを提案し、タグ 'ajax'と' jquery'を使ってスタックに投稿することはできません。 – Alex

関連する問題