页面导航自定义

时间:2014-05-13 03:14:23

标签: php

我的搜索结果页面每页显示20行。如果使用会话变量在搜索结果中有超过20行,我尝试创建一种导航页面的方法。我的问题是我的导航变量在第一次运行后似乎变空了,即使它应该在提交时获取值,因为我只是获取提交按钮的值。它没有显示任何错误,也没有显示它应该如何工作所以我想请求一些关于我的逻辑似乎出错的帮助。这是代码:

查看页面:

if(isset($pageCount)){      //it has more than one page
        if($pageCount == $currentPage && $pageCount > 1){   //currently at last page
            echo "<form name='searchCompanyFiles'  class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/search_info/searchCompany' method = POST>
                <input type = 'hidden' name = 'filter' value = '".$filter."'/>
                <input type = 'hidden' name = 'searchQuery' value = '".$searchQuery."'/>
                <input type = 'hidden' name = 'pageCount' value = '".$pageCount."'/>
                <input type = 'hidden' name = 'currentPage' value = '".$currentPage."'/>
                <input type = 'submit' name = 'navigation' value = 'Prev'/>
            </form>";
        }

        else if($pageCount == $currentPage){                //assuming one page only

        }

        else if($pageCount > 1 && $currentPage > 1){        //somewhere in the middle
            echo "<form name='searchCompanyFiles'  class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/search_info/searchCompany' method = POST>
                <input type = 'hidden' name = 'filter' value = '".$filter."'/>
                <input type = 'hidden' name = 'searchQuery' value = '".$searchQuery."'/>
                <input type = 'hidden' name = 'pageCount' value = '".$pageCount."'/>
                <input type = 'hidden' name = 'currentPage' value = '".$currentPage."'/>
                <input type = 'submit' name = 'navigation' value = 'Prev'/>
                <input type = 'submit' name = 'navigation' value = 'Next'/>
            </form>";
    /*      echo "<form name='searchCompanyFiles'  class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/search_info/searchCompany' method = POST>
                <input type = 'hidden' name = 'filter' value = '".$filter."'/>
                <input type = 'hidden' name = 'searchQuery' value = '".$searchQuery."'/>
                <input type = 'hidden' name = 'pageCount' value = '".$pageCount."'/>
                <input type = 'hidden' name = 'currentPage' value = '".$currentPage."'/>
                <input type = 'hidden' name = 'navigation' value = 'next'/>
                <input type = 'submit' value = 'Next'/>
            </form>";*/
        }
        else if($pageCount > 1 && $currentPage == 1){   //currently at first page
            echo "<form name='searchCompanyFiles' class='form-inline' enctype='multipart/form-data' action = '/DTS/index.php/search_info/searchCompany' method = POST>
                    <input type = 'hidden' name = 'filter' value = '".$filter."'/>
                    <input type = 'hidden' name = 'searchQuery' value = '".$searchQuery."'/>
                    <input type = 'hidden' name = 'pageCount' value = '".$pageCount."'/>
                    <input type = 'hidden' name = 'currentPage' value = '".$currentPage."'/>
                    <input type = 'submit' name = 'navigation' value = 'Next'/>
            </form>";
        }

    }
    else{
        echo "Page count not updating";
    }

控制器代码:

if(isset($navigation)){         
            $navigation = $_POST['navigation'];         //after initial search to determine if user
        }                                               //went forward of back
        else{
            echo "SEARCH";
            $navigation = '';
        }
        $pageCount = $_POST['pageCount'];           //
        $currentPage = $_POST['currentPage'];

        $searchQuery = trim($_POST['searchQuery']);
        $filter = $_POST['filter'];

        if(empty($searchQuery)){
            $data['details'] = $this->search_form->searchAllCompany($navigation, $pageCount, $currentPage);
        }

        else{
            switch($filter){
                case 1: 
                        $this->form_validation->set_rules('searchQuery', 'Search Query', 'is_natural');
                        if($this->form_validation->run()==FALSE){
                            $_SESSION['fail'] = 'Failed Search';
                        }
                        else{
                            $data['details'] = $this->search_form->searchCompanyId($searchQuery);

                        }

                        break;
                case 2: $this->form_validation->set_rules('searchQuery', 'Search Query', 'callback_alpha_dash_space');
                        if($this->form_validation->run()==FALSE){
                            $_SESSION['fail'] = 'Failed Search';
                        }
                        else{
                            $data['details'] = $this->search_form->searchCompanyName($searchQuery);
                        }
                        break;
                case 3: $this->form_validation->set_rules('searchQuery', 'Search Query', 'callback_alpha_dash_space');
                        if($this->form_validation->run()==FALSE){
                            $_SESSION['fail'] = 'Failed Search';
                        }
                        else{
                            $data['details'] = $this->search_form->searchCompanyAcronym($searchQuery);
                        }
                        break;
                default:
                        $data['details'] = $this->search_form->searchAllCompany($navigation, $pageCount, $currentPage);

                        // $data['details'] = $this->search_form->searchAllCompany();
                        break;
            }

型号代码:

$rowsC[] = array();

        if(!empty($pageCount)){     //if there is something to navigate through
            //unset($_SESSION['pageCount']);
            $start = $currentPage * 20;     
            $count = $this->db->query("SELECT * from company ORDER BY id"); 
            $output = $this->db->query("SELECT * from company ORDER BY id LIMIT $start, 20");
            if(strcmp(trim($navigation), "Prev") == 0){
                echo "DID IT ENTER HERE?";
                $currentPage--;
            }else if(strcmp(trim($navigation), "Next") == 0){
                echo "IT ENTERED HERE!";
                $currentPage++;
            }
            echo "Value of navigation: ".$navigation;

                    //update current page
        /*  if($output->num_rows()%20 == 0){
                $_SESSION['pageCount'] = (int)$count->num_rows()/20;        //even count
            }
            else{
                $_SESSION['pageCount'] = (int)($count->num_rows()/20) + 1;  //odd count
            }*/
        }
        else{   //initial search

        $count = $this->db->query("SELECT * from company ORDER BY id");
        $output = $this->db->query("SELECT * from company ORDER BY id LIMIT 0, 20");

        $currentPage = 1;
            if($count->num_rows()%20 == 0){
                $pageCount = (int)$count->num_rows()/20;        //even count
            }
            else{
                $pageCount = (int)($count->num_rows()/20) + 1;  //odd count
            }
        }
        $i = 0;

        if ($output->num_rows() > 0) {
            foreach($output->result_array() as $rowC){
                $rowsC[$i]['id'] = $rowC['id'];
                $rowsC[$i]['name'] = $rowC['name'];
                $rowsC[$i]['address'] = $rowC['address'];
                $rowsC[$i]['telNum'] = $rowC['telNum'];
                $rowsC[$i]['faxNum'] = $rowC['faxNum'];
                $rowsC[$i]['email'] = $rowC['email'];
                $rowsC[$i]['website'] = $rowC['website'];
                $rowsC[$i]['acronym'] = $rowC['acronym'];
                $i++;
            }
            return $rowsC;
        }
        return false;

1 个答案:

答案 0 :(得分:0)

这一行是导致我没有获得导航值的原因

if(isset($navigation)){         
            $navigation = $_POST['navigation'];        
}     

应该是这样的:

if(isset($_POST['navigation'])){         
            $navigation = $_POST['navigation'];        
}