Welcome Guest, Not a member yet? Register   Sign In
URI puzzle
#1

[eluser]incog03[/eluser]
I've made a website which grabs a bunch of results and paginates them, 10 results per page. The URI ends in /10 or /20 or /30 etc. But what I also want to do is get results based on links on my front page with categories, ie basketball, netball, soccer. Clicking these links will bring up threads based on these values only.

My question is - how do I pass the value "basketball" back to the controller/model if the URI is already being used to paginate the results? Each time i do it my queries fail because the query start point is "basketball", instead of the normal 0 10 20 etc, and the result limit is unchanaged at 10.

I guess i'm looking for a way to pass 2 variables back to the controller, so that I can use 1 function to handle all the links and database queries instead of individual functions for each link on my website.

I hope i've been clear, I'm trying to make this sound as clear as possible and it's surprisingly difficult to do so!

Code:
$this->load->library('pagination');
        $this->load->model('query');
        $this->load->model('search');
        
        $config['uri_segment'] = 3;
        $config['base_url'] = base_url().'search/index';
        $config['per_page'] = 10;
        $config['total_rows'] = $this->query->countResult();
        $config['num_links'] = 8;

        $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;
        $data['result'] = $this->query->grab_result_list($config['per_page'],$page);
        $this->pagination->initialize($config);            
        
        $data['link'] = $this->pagination->create_links();
        
        $searchdata = $this->search->searchresults();

My query would look like this;
Quote: $query = $this->db->query("SELECT * FROM game
INNER JOIN sportType st
ON st.userID = game.userID
WHERE st.classification = 'golf'
LIMIT $start, $limit");

where the sport classification may change from golf to tennis to football etc etc. How do I pass these different variables back to the same function - along with the pagination data?
#2

[eluser]osci[/eluser]
in a hurry

use another segment for your filter
pass for example the id
base_url.search/index/$id
uri_segment +1
grab_result_list should take in account the id
#3

[eluser]incog03[/eluser]
I was trying to do that earlier but it refused to work so I gave up, however i never did exactly what you said:
Code:
$class = $this->uri->segment(3);
$config['base_url'] = base_url().'search/index/$class';

Because it's important for other users who have my issue in the future i've updated the code
Code:
function query(){
$this->load->library('pagination');
        $this->load->model('query');
        $this->load->model('search');

$class = $this->uri->segment(3);
        
        $config['uri_segment'] = 4;
        $config['base_url'] = base_url().'search/index/$class';
        $config['per_page'] = 10;
        $config['total_rows'] = $this->query->countResult($class);
        $config['num_links'] = 8;

        $page = ($this->uri->segment(4))? $this->uri->segment(4) : 0;
        $data['result'] = $this->query->grab_result_list($config['per_page'],$page, $class);
        $this->pagination->initialize($config);            
        
        $data['link'] = $this->pagination->create_links();
        
        $searchdata = $this->search->searchresults();
        $this->load->view('header');
        $this->load->view('search', $searchdata);
        $this->load->view('results', $data);
        $this->load->view('searchright');
        $this->load->view('footer');

Code:
function grab_result_list($limit, $start, $class){
    
               $query = $this->db->query("SELECT * FROM game
                        INNER JOIN sportType st
                        ON st.userID = game.userID
                        WHERE st.classification = '$class'
                        LIMIT $start, $limit");
                                
        if($query->num_rows()>0)
        {
            foreach ($query->result() as $row)
            {
                $data[] = $row;
            }
            return $data;
        }
        else
        {
            return FALSE;
        }
    }

Thanks for taking the time to answer! Was most helpful, I hope the resulting changes to the code I've provided above is as useful for others as it was for me!




Theme © iAndrew 2016 - Forum software by © MyBB