0

私は、一連のオプションのフィールドを取り、データベースに対してクエリを実行して、選択したフィールドに基づいて結果を返す codeigniter のアプリに取り組んでいます。これらの結果は、codeigniter ページネーション ライブラリを使用してページ付けされます。

ページ付けは正常に機能し、結果はページ付けされます。問題は、たとえば、性別を「男性」にして男性の結果のみが返される場合です。最初のページは完全に機能しますが、create_links() 関数はすべての結果のページをレンダリングしますテーブル、およびページを変更すると、db->get() 関数のすべての「where」パラメーターは無視されます。これに関するアドバイスは大歓迎です。

コード:

コントローラ:

public function searchcharacter() {

        $data = $this->input->post();

        $gender = $data['gender'];
        $age = $data['approx_age'];
        $hairColour = $data['hair_colour'];
        $hairLength = $data['hair_length'];
        $eyeColour = $data['eye_colour'];
        $earType = $data['ear_type'];
        $weapons = $data['weapons'];

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

        $config['base_url'] = 'http://localhost/ci-animedb/site/searchcharacter';
        $config['total_rows'] = $this->db->get('characters')->num_rows();
        $config['per_page'] = 10;
        $config['uri_segment'] = 3;
        $config['num_links'] = 20;

        $this->pagination->initialize($config);

        $this->load->model('get_db');
        $results['characters'] = $this->get_db->getCharacterList($gender, $age, $hairColour, $hairLength, $eyeColour, $earType, $weapons, $config['per_page']);

        $this->load->view('header');
        $this->load->view('characterlist', $results, FALSE);
        $this->load->view('footer');

}

モデル:

function getCharacterList($gender, $age, $hairColour, $hairLength, $eyeColour, $earType, $weapons, $limit) {

    if ($gender != "None" && !empty($gender))
    {
      $this->db->where('gender', $gender);
    }

    if ($age != "None" && !empty($age))
    {
      $this->db->where('approx_age', $age);
    }

    if ($hairColour != "None" && !empty($hairColour))
    {
      $this->db->where('hair_colour', $hairColour);
    }

    if ($hairLength != "None" && !empty($hairLength))
    {
      $this->db->where('hair_length', $hairLength);
    }

    if ($eyeColour != "None" && !empty($eyeColour))
    {
      $this->db->where('eye_colour', $eyeColour);
    }

    if ($earType != "None" && !empty($earType))
    {
      $this->db->where('ear_type', $earType);
    }

    if ($weapons != "None" && !empty($weapons))
    {
      $this->db->where('weapons', $weapons);
    }

    $query = $this->db->get('characters', $limit, $this->uri->segment(3));
    return $query->result();
}

意見:

<div class="container">

    <div class="row">
        <div class="span12">
            <img src="<?php echo base_url(); ?>img/banner1.png" alt="AnimeDB.me" />
        </div>
    </div>

    <div class="row">
      <div class="span12" style="height:1px; background-color: #cccccc; margin-top: 20px; margin-bottom: 15px;"></div>
    </div>

  <div class="row">
    <div class="span12" id="ajaxcontainer">

      <table class='table table-striped' id='resulttable' >
        <thead>
          <th>Image</th>
          <th>Name</th>
          <th>Anime</th>
        </thead>
        <tbody>

          <?php

            foreach ($characters as $row) {
              echo "<tr class='resulttr'><td><a href='" . base_url('site/character'). '/' . $row->character_id . "' ><image height=140 width=140 src='" . base_url('img/characterimage') . "/" . $row->file_path . "' /></a></td>";
              echo "<td>" . $row->character_name . "</td>";
              echo "<td>" . $row->anime . "</td>";
              echo "<td class='rowid' style='display:none;'>" . $row->character_id . "</td></tr>";
            }

          ?>

        </tbody>
      </table>

    <div class="form-actions">
      <?php echo $this->pagination->create_links(); ?>
    </div>

    </div>
  </div>

</div> <!-- /container -->
4

1 に答える 1