入力データに基づいてデータベースからフォームにデータを取り出しています。
例:フォームで、私が姓を検索すると、姓のデータを取得する必要があります。 ANDまたはOR演算子ボタンを使用してすべてのフィールド検索が成功しました。次のレコードの検索でデータを取り出して、空のフィールドを表示しているレコードに最初のレコードが表示されません。
しかし、1つのレコードだけを取得しているにもかかわらず、検索基準ごとに別のレコードを取得していないページネーションには問題があります。
ここでは、ページを含めるためにテンプレートライブラリを使用しています。ここでは上記のフォームの画像で
私は検索レコードごとに同じview..andの改ページのリンクに表示されるはずの任意のフィールドにテキストを入力することにより、特定のレコードを検索する場合は、必要
初期フォームは空です
モデル:
public function search_record()
{
$id= $this->input->get('id');
$name= $this->input->get('lname');
$fname= $this->input->get('fname');
$pdate= $this->input->get('pdate');
$adate= $this->input->get('adate');
$client= $this->input->get('client');
$bw= $this->input->get('bw');
$color= $this->input->get('color');
$digital= $this->input->get('digital');
$famous= $this->input->get('famous');
$place= $this->input->get('place');
$concept= $this->input->get('concept');
$thing= $this->input->get('thing');
$oldid= $this->input->get('oldid');
$note= $this->input->get('note');
// $condition = array('id_photo' =>$id);
// $condition2=array('lastname'=>$name);
// $condition3=array('firstname'=>$fname);
// $condition4=array('photo_date'=>$pdate);
//
$this->db->select('photo_id,lastname,firstname,bw,color,digital,famous,place,concept,thing,client,photo_date,add_date,note,id_photo');
$this->db->from('tblphotomstr');
$strWhere = "";
if($id != NULL){
$strWhere = "id_photo like "."'%$id%'";
}
if($name != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and lastname like "."'%$name%'";
}else{
$strWhere = "lastname like "."'%$name%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or lastname like "."'%$name%'";
}else{
$strWhere = "lastname like "."'%$name%'";
}
}
}
if($fname != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and firstname like "."'%$fname%'";
}else{
$strWhere = "firstname like "."'%$fname%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or firstname like "."'%$fname%'";
}else{
$strWhere = "firstname like "."'%$fname%'";
}
}
}
if($pdate != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and photo_date like "."'%$pdate%'";
}else{
$strWhere = "photo_date like "."'%$pdate%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or photo_date like "."'%$pdate%'";
}else{
$strWhere = "photo_date like "."'%$pdate%'";
}
}
}
if($adate != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and add_date like "."'%$adate%'";
}else{
$strWhere = "add_date like "."'%$adate%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or add_date like "."'%$adate%'";
}else{
$strWhere = "add_date like "."'%$adate%'";
}
}
}
if($client != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$client%'";
}else{
$strWhere = "client like "."'%$client%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$client%'";
}else{
$strWhere = "client like "."'%$client%'";
}
}
}
if($bw != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$bw%'";
}else{
$strWhere = "client like "."'%$bw%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$bw%'";
}else{
$strWhere = "client like "."'%$bw%'";
}
}
}
if($color != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$color%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$color%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
}
if($digital != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$color%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$digital%'";
}
}
}
if($famous != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$famous%'";
}else{
$strWhere = "client like "."'%$famous%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$digital%'";
}else{
$strWhere = "client like "."'%$digital%'";
}
}
}
if($place != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$place%'";
}else{
$strWhere = "client like "."'%$place%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$place%'";
}else{
$strWhere = "client like "."'%$place%'";
}
}
}
if($concept != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$concept%'";
}else{
$strWhere = "client like "."'%$concept%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$concept%'";
}else{
$strWhere = "client like "."'%$concept%'";
}
}
}
if($thing != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$thing%'";
}else{
$strWhere = "client like "."'%$thing%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$thing%'";
}else{
$strWhere = "client like "."'%$thing%'";
}
}
}
if($oldid != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and client like "."'%$oldid%'";
}else{
$strWhere = "client like "."'%$oldid%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or client like "."'%$oldid%'";
}else{
$strWhere = "client like "."'%$oldid%'";
}
}
}
if($note != NULL){
$opt = $this->input->get('and');
if($opt==1)
{
if($strWhere != "")
{
$strWhere = $strWhere." and note like "."'%$note%'";
}else{
$strWhere = "note like "."'%$note%'";
}
}
if($opt==2)
{
if($strWhere != ""){
$strWhere = $strWhere." or note like "."'%$note%'";
}else{
$strWhere = "note like "."'%$note%'";
}
}
}
コントローラ:
public function search()
{
print_r($this->search_model->search_record());
$limit = 1;
$config["base_url"] = base_url('Home/search');
$config['total_rows'] = $this->db->count_all('tblphotomstr');
$config["per_page"] = $limit;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['cur_tag_open'] = ' <li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$offset = 0;
if (!empty($_GET['per_page'])) {
$pageNo = $_GET['per_page'];
$offset = ($pageNo - 1) * $limit;
}
$data = array();
$this->db->limit($limit, $offset);
$data['records']= $this->search_model->search_record();
print_r($data);
$this->template->set('title', 'Edit Record');
$this->template->load('default_layout', 'contents' , 'search', $data);
}
のplsはあなたの全体のモデルコードとあなたの改ページコードを投稿ホープ - 私はすべてのあなたの思うのでgetパラメータがページ2などをクリックした後に失われてしまっている...そして別の推奨事項 - 適切にquerybuilderを使用している - クエリ全体が完全に安全でない – sintakonte
ビューで使用した(
私はいくつかの説明とフォームイメージと@ sintakonteを更新...もしplsガイドをクリアしない場合.. –