Welcome Guest, Not a member yet? Register   Sign In
Pagination - Not working... again!
#2

[eluser]Bramme[/eluser]
Dunno if this is the solution, but I would restructure the way you're approaching your $keyword handling. I would go about it this way:

controller:
Code:
<?php

class search extends Controller {

    function search()
    {

        parent::Controller();

        $this->load->model('mdl_search');
        $this->load->helper('url');
        
        $data['title'] = "MY SEARCH FUNCTION";
        $this->load->vars($data);

    }

    function index()
    {

        if($this->input->post('submit') != false)
        {
            $keyword = $this->input->post('keyword', true); //parses it through the XSS filter
            redirect("/search/keyword/$keyword");
        }
        
        $this->load->view('searchform');
    }
    
    function keyword()
    {
        
        $keyword = $this->uri->segment(3, null);
        
        if(!isset($keyword))
        {
            redirect('/search'); // extra precaution
        }
        
        $data['count_results'] = $this->mdl_search->countResults($keyword);

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

        $config['base_url'] = site_url('search/keyword/' . url_title($keyword));
        $config['total_rows'] = $data['count_results'];
        $config['uri_segment'] = '4';
        $config['per_page'] = '10';

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

        $offset = $this->uri->segment(4, 0);

        $data['search_results'] = $this->mdl_search->getSearchResults($keyword, $config['per_page'], $offset);

        $this->load->view('arcade/header');

        $this->load->view('arcade/search', $data);

        $this->load->view('arcade/footer');

    }



}

?>
searchform view:
Code:
<form action="/search/" method="post">
    <input type="text" name="keyword" />
    <input type="submit" name="submit" value="Submit search" />
</form>
and your final view
Code:
<div class="search">

        <h2>&lt;?= $title;?&gt;</h2>

            <div class="pagination">&lt;?php echo $this->pagination->create_links(); ?&gt;</div>

            <table class="search-results">

                    <tr class="headerRow">

                        <th class="gameTitle"><a href="#"><span>Game Title</span></a></th>

                        <th class="active"><a href="#"><span>Players</span></a></th>

                        <th><a href="#"><span>Rating</span></a></th>

                        <th><a href="#"><span>Reviews</span></a></th>

                        <th><a href="#"><span>Play Type</span></a></th>

                    </tr>

                    

                        &lt;? foreach ($search_results as $search_result): ?&gt;

                            <tr class="alt">

                                <td class="title"><a href="#"><img src="&lt;?php echo base_url() ?&gt;images/img/&lt;?php echo $search_result['nameid'];?&gt;.png" alt="&lt;?php echo $search_result['name'];?&gt;" width="60" height="50"></a><div class="fltLft"><a href="#">&lt;?php echo $search_result['name'];?&gt;</a><br />&lt;?php echo $search_result['desc'];?&gt;</div></td>

                                <td class="players">1,262</td>

                                <td class="ratings"><b>5.00</b><br />out of 5.0</td>

                                <td class="reviews"><span class="up">72%</span><br />491 reviews</td>

                                <td><a href="#" class="btnSearchPlayNow clearLink">play now</a><a href="/servlet/DownloadEcommTracker?sku=texttwist&promoCode=SearchList" class="#">download</a></td>

                            </tr>

                        &lt;? endforeach; ?&gt;

            </table>

    </div>
(now there's no if)

Try this. I hope it works, didn't test it.

note: you should also handle "no search results"


Messages In This Thread
Pagination - Not working... again! - by El Forum - 07-16-2008, 01:02 AM
Pagination - Not working... again! - by El Forum - 07-16-2008, 03:29 AM
Pagination - Not working... again! - by El Forum - 07-16-2008, 09:08 AM
Pagination - Not working... again! - by El Forum - 07-16-2008, 09:35 AM
Pagination - Not working... again! - by El Forum - 07-16-2008, 11:12 AM
Pagination - Not working... again! - by El Forum - 07-16-2008, 11:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB