Welcome Guest, Not a member yet? Register   Sign In
help with pagination
#1

[eluser]nagata[/eluser]
ok guise so I have a forum and I need to implement pagination SOMEHOW
I have been trying to make the native CI pagination class to work but failed...
You can see it here http://zetaworks.myvnc.com/index.php/for...essages/9/
So if someone could help me make it work I would be very happy!
the code's:
Model
Code:
function get_messages($validtopic,$items) {
$threadsql = "SELECT messages.*, users.username FROM messages, users WHERE messages.user_id = users.user_id AND messages.topic_id = '$validtopic' ORDER BY messages.date";
  
$threadresult = $this->db->query($threadsql);
if ($threadresult->num_rows() > 0) {
  return $threadresult->result_array();
  }
else {
  return FALSE;
}
}
Controller
Code:
function viewmessages()
{
  $data['css'] = $this->css;
  $data['base'] = $this->base;
  $this->load->model('Listings_model');
  $mytopic_id = $this->uri->segment(3, 0);
$start_page = $this->uri->segment(4, 0);

// /forum/msg/(:num)
   //echo $mytopic_id;
  
   if (($mytopic_id !== NULL) && (is_numeric($mytopic_id))) {
    $validtopic = $mytopic_id;
    $data['validtopic'] = $validtopic;
    $msgname = $this->Listings_model->get_msg_name($validtopic);
    $data['msgname'] = $msgname;
    //print_r($data['msgname']);

$messagesresult = $this->Listings_model->get_messages($validtopic,$start_page);
$data['reply_count'] = count($messagesresult);
    //print_r($messagesresult);
    if ($messagesresult != 0) {
     $data['messagesresult'] = $messagesresult;
    }
    else {
    echo "BOO HOO";
    }

$data['title'] = 'View Messages';
$this->load->view('templates/header_template', $data);
$this->load->view('forum/viewmessages',$data);
$this->load->view('templates/footer_template');
//Load page contents into template
    ////$this->template->display('viewmessages', $data);
    //////
} else {
    redirect('/forum/');
    return;
  }

}
View
Code:
<?php

$topicid= $this->uri->segment(3,0);
$config['base_url'] = "/index.php/forum/viewmessages/$topicid";
$config['total_rows'] = $reply_count;
$config['per_page'] = 10;

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

echo $this->pagination->create_links();

?>
So guise help me Big Grin
#2

[eluser]InsiteFX[/eluser]
This code should be in your controller not your view
Code:
$topicid= $this->uri->segment(3,0);
$config['base_url'] = "/index.php/forum/viewmessages/".$topicid;
$config['total_rows'] = $reply_count;
$config['per_page'] = 10;

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

This is all that you need in your view file.
Code:
<?php echo $this->pagination->create_links(); ?>

#3

[eluser]nagata[/eluser]
yes thanks sadly your suggestion wouldnt help,
I had solved this problem before your reply and my solution was different
the one you told I tried already did not work.




Theme © iAndrew 2016 - Forum software by © MyBB