Welcome Guest, Not a member yet? Register   Sign In
Pagination [doing my head in]...anyone...please?
#1

[eluser]Wonder Woman[/eluser]
Hi,

I basically can't get the pagination bit to work, I did before I changed my database query and now I'm stuck.

My model looks like:

Code:
function get_properties($limit, $offset) {
   $location = $this->session->userdata('location');
   $property_type = $this->session->userdata('property_type');
   if($property_type == 0)
   {
      $sql = "SELECT * FROM properties ";
   }
   // more queries here
   $sql .= " LIMIT ".$limit.", ".$offset.";";
   $query = $this->db->query($sql);
   if($query->num_rows() > 0) {
      $this->session->set_userdata('num_rows', $query->num_rows());
      return $query->result_array();    
      return FALSE;
      }
   }
}

and my controller looks like:

Code:
function results() {
   $config['base_url'] = base_url().'/properties/results';
   $config['per_page'] = '3';
   $data['properties_results'] = $this->properties_model->get_properties($config['per_page'], $this->uri->segment(3));
   $config['total_rows'] = $this->session->userdata('num_rows');
   $this->pagination->initialize($config);
   $config['full_tag_open']='<div id="pages">';
   $config['full_tag_close']='</div>';
   $data['links']=$this->pagination->create_links();
   $this->load->view('properties_results',$data);
}

please help...its screwing up!
#2

[eluser]bretticus[/eluser]
Want to provide...oh maybe...an error message or two? Smile

By the way, what is the purpose of...

Code:
if($property_type == 0)
   {
      $sql = "SELECT * FROM properties ";
   }

...because, unless that if statement is true, you have an incomplete query as it is followed by...

Code:
// more queries here
   $sql .= " LIMIT ".$limit.", ".$offset.";";
   $query = $this->db->query($sql);

...and that may be the source of "its screwing up!" So, again, please provide your error message(s).

Cheers!
#3

[eluser]Wonder Woman[/eluser]
If you see the comment, it says there is more queries, of course I'm not pulling back an incomplete sql search.

Its just too long to post it all on here.

I realise the error is to do with the offset and total of rows from the query.
#4

[eluser]bretticus[/eluser]
[quote author="fpp" date="1282934212"]If you see the comment, it says there is more queries, of course I'm not pulling back an incomplete sql search.

Its just too long to post it all on here.[/quote]

Okay, fair enough. But why post incomplete code here and no error messages? Who's to know that "more queries" isn't referring to the code below it!? You didn't even explain what you expected vs. what is happening. Help us help you! :-)

[quote author="fpp" date="1282934212"]I realise the error is to do with the offset and total of rows from the query.[/quote]

Again, what is the error? An error message, you're getting something you didn't expect, what?
#5

[eluser]Wonder Woman[/eluser]
Its ok, I have just fixed it Smile It was to do with the total rows returned and the offset number but its all sorted now.

Thanks though.
#6

[eluser]bretticus[/eluser]
Glad you got it sorted out. Just a suggestion about posting questions in the future, you have to assume that people can not, in fact, read your mind. You have to assume that ppl reading your post are looking at your problem for the very first time (because we are!) "Here's some code and it's not working", is not helpful. I'm not trying to be a jerk here. This is good constructive criticism here meant for your benefit, really. Smile (Okay, I did come across a bit jerky in my initial response...sorry.)
#7

[eluser]Wonder Woman[/eluser]
That's ok - I totally get what you mean, I'm new to using forums etc so I never know what's enough information or not. Smile




Theme © iAndrew 2016 - Forum software by © MyBB