Welcome Guest, Not a member yet? Register   Sign In
Pagination config problem
#21

[eluser]LuckyFella73[/eluser]
I don't know if you are doing something wrong at all! Do you
expect more results than you get? I mean if you get results
then your code works basically. In case you expect more than
the results you get you have to look at your query. If I where
you I would echo
Code:
$this->db->last_query();
and do some tests with phpmyadmin to be sure my query is right.
#22

[eluser]ToXXXic[/eluser]
I think I found where the problem is, but I am not sure how to solve it:

the
Code:
echo $this->db->last_query();
return
Code:
SELECT * FROM (`company`) LIMIT 4

I am not sure why is it adding the LIMIT: here is the code I use to get the data

Code:
$query=$this->db->get('company',$perpage, $this->uri->segment(3));

the $perpage is passed from $config['per_page'].

Thanks

T
#23

[eluser]SPeed_FANat1c[/eluser]
[quote author="ToXXXic" date="1289862691"]I think I found where the problem is, but I am not sure how to solve it:

the
Code:
echo $this->db->last_query();
return
Code:
SELECT * FROM (`company`) LIMIT 4

I am not sure why is it adding the LIMIT: here is the code I use to get the data

Code:
$query=$this->db->get('company',$perpage, $this->uri->segment(3));

the $perpage is passed from $config['per_page'].

Thanks

T[/quote]

http://ellislab.com/codeigniter/user-gui...tml#select
#24

[eluser]LuckyFella73[/eluser]
Maybe you can try it the following way. You can write it shorter
and it's not tested but it should work:
Code:
# CONTROLLER:
function viewSearch()
{
    $this->load->model('search_model');
    $this->load->library('pagination');
    $this->load->library('table');

    $config['base_url']='http://localhost/index.php/main/viewSearch/';
    
    $total_rows = $this->search_model->get_total_rows();
    $config['total_rows'] = $total_rows;

    $config['per_page'] = 5;
    $config['num_links'] = 10;
    $config['uri_segment'] = 3;
    $config['full_tag_open'] = '<div id="pagination">';
    $config['full_tag_close'] = '</div>';

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

    //echo $this->search_model->total_rows;
    
    $query = $this->search_model->getCompany($config['per_page']);
    $data['records'] = $query;

    $data['main_content'] = 'search_view';
    $this->load->view('includes/master',$data);
}


# Model:
class Search_model extends Model
{
    function Search_model()
    {
        parent::Model();
    }

    function get_total_rows()
    {
        $this->db->like('name',$this->input->post('search'));
        $this->db->or_like('business',$this->input->post('search'));
        $this->db->get('company');
        
        return $this->db->count_all_results();
    }
    
    function getCompany($perpage)
    {
        $this->db->like('name',$this->input->post('search'));
        $this->db->or_like('business',$this->input->post('search'));
        
        $query = $this->db->get('company',$perpage, $this->uri->segment(3));
        
        if($query)
        {
            return $query->result();
        }
    }
}
#25

[eluser]CI_Newb[/eluser]
Well I got it working using the above method of 1 query to get the total rows, then another for the pagination but I've come across another problem

So I enter some search criteria into my form and the results do return properly along with the pagination as expected.

Problem is when I go to another page within the pagination, its re querying the database with an empty form. I either need to get the values in the form to stick throughout the pagination pages or ..... I dunno actually.
#26

[eluser]SPeed_FANat1c[/eluser]
I guess this is because of sentences like this:

Code:
$this->db->or_like('business',$this->input->post('search'));

it takes data from $_POST array. And when you click on pagination link, there is no more data in $_POST (effect like the form is empty). You need to pass the data to query somehow different. You need to use $this->input-post only ionitially then save those input values or something so you could use them again when page is clicked.
#27

[eluser]CI_Newb[/eluser]
[quote author="SPeed_FANat1c" date="1291039423"]I guess this is because of sentences like this:

Code:
$this->db->or_like('business',$this->input->post('search'));

it takes data from $_POST array. And when you click on pagination link, there is no more data in $_POST (effect like the form is empty). You need to pass the data to query somehow different. You need to use $this->input-post only ionitially then save those input values or something so you could use them again when page is clicked.[/quote]

Exactly. Thats why I thought of using a simple hidden form that grabs the values from the search.

Just need to figure out a way to make the pagination links submit that hidden form. So far no luck
#28

[eluser]LuckyFella73[/eluser]
I would recommend to do this by using session variables.
Otherwise you would have to modify the pagination library
to create one form for each pagination link. Sounds not like
a clean solution ..
There are some posts about how to solve this issue around
this forums.
#29

[eluser]SPeed_FANat1c[/eluser]
I can think of one solution with long urls:
www.domain.com/results/parameter1/param2/paran3/pagination_offset

so when you click submit then you pass input data to url and sentences like
Code:
$this->db->or_like('business',$this->input->post('search'));

repalce with

Code:
$this->db->or_like('business',$this->uri->segment(x));

x - is the parameter from segment
#30

[eluser]CI_Newb[/eluser]
[quote author="SPeed_FANat1c" date="1291043337"]I can think of one solution with long urls:
www.domain.com/results/parameter1/param2/paran3/pagination_offset

so when you click submit then you pass input data to url and sentences like
Code:
$this->db->or_like('business',$this->input->post('search'));

repalce with

Code:
$this->db->or_like('business',$this->uri->segment(x));

x - is the parameter from segment[/quote]

I would but this url would have like 20ish segments lol




Theme © iAndrew 2016 - Forum software by © MyBB