Welcome Guest, Not a member yet? Register   Sign In
Pagination Issue
#1

[eluser]Kraig[/eluser]
I am having some issues displaying the pagination with my query results. The results were working how they were supposed too, but not when I try to add CI pagination. The pagination library and url helper are loaded in the constructor
My Model:
Code:
public function cat_page($limit, $start, $catID)
{
  if($catID == 0){
   $query = $this->db->query('SELECT * FROM upload LIMIT '.$limit.', '.$start);
  }else{
   $query = $this->db->query('SELECT * FROM upload WHERE category = '.$catID.'  LIMIT '.$limit.', '.$start);
  }
  $val = $query->result_array();
  $this->num_rows = $query->num_rows;

  if ($this->num_rows() > 0) {
        foreach ($query->result() as $row) {
           $data[] = $row;
        }
        return $data;
   }
   return false;
}

My home controller function being called:
Code:
public function catSelector()
{
  $this->catID = $_GET['cat'];
    // Pagination!!!
   $config = array();
   $config["base_url"] = base_url() . "home/";
   $config["total_rows"] = $this->membership_model->num_rows;
   $config["per_page"] = 5;
   $config["uri_segment"] = 3;

   $this->pagination->initialize($config);
   $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
   $data["results"] = $this->membership_model->
        cat_page($config["per_page"], $page, $this->catID);
   $data["links"] = $this->pagination->create_links();
  
  echo '<table cellspacing="0" cellpadding="0">
   <tr>
    <th width="50%">File Name:</th>
    <th width="30%">File Size:</th>
    <th>Download Link:</th>
   </tr>';

  $c = true;
  foreach($data["results"] as $files){
   echo '<tr'.(($c = !$c)?' class="odd"':'').">
    <td>$files[name]</td>
    <td>$files[size]</td>
    <td><a href='$files[location]'>Download</a></td>
   </tr>";
  }
        
       echo '</table><br ';
    
    $this->load->view("home", $data);
}

I'm also having an issue with the the last line of the controller function ($this->load->view("home", $data)Wink.

My View: An Ajax feature that grabs the uploads based on category. This works....just not with the new editions of the pagination Sad
Code:
......
[removed]
function showUser(str) {
  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
   document.getElementById("tars")[removed]=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","home/catSelector?cat="+str,true);
  xmlhttp.onload = table_design;
  xmlhttp.send();
}
[removed]
.......

This is my home page and so in my index() function I load a template..wont that cause re-directs?. Does it look like I'm on the right track?? Thanks for your help!!
#2

[eluser]DarkManX[/eluser]
Try to feed the pagination with data manually. Create an array in the code and give it to the library.
Btw: dont put out html in the controller, just load a view to display the page. I would suggest you to use a js framework, not just using pure js.
#3

[eluser]Kraig[/eluser]
Right now my AJAX Select Category, along with the requested results and pagination numbers works. My issue now is the $config['base_url'] as you can see below. This function and the index are both in my home controller.
Code:
public function catSelector()
{
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   $catID = $_POST['cat'];
  }else{
   $catID = 0;
  }
  
  // Pagination!!!
  $data['things'] = $this->membership_model->cat_page($catID);

  $config['base_url'] = base_url().'home/catSelector';
  $config['total_rows'] = $this->membership_model->num_rows;
  $config['per_page'] = 5;
  $this->pagination->initialize($config);
  
  $data['pagination'] =  $this->pagination->create_links();
  echo $this->membership_model->num_rows;
  $this->load->view('test', $data);
}

So everything works..and then I click on one of the links for the next page, and I loose all of my index() function data. Which of course has my template...so catSelector is the function above and it runs then loads test.php, which is merely a page to display the query results. How can I load the test.php without losing my index template when a page link is clicked? Below is my index function
Code:
function index()
{
  // Grabbing Categories
  $q = $this->upload_model->category();
        $data['fileCategory'] = $q;
  
  // Grabbing topMembers info
  $q = $this->membership_model->user_info();
        $data['user_info'] = $q;
  //$this->catSelector();
  
  // Grabbing news
  $q = $this->news_model->home_news();
        $data['home_news'] = $q;
  
  $is_logged_in = $this->loggedin->loggedin();
  if(!$is_logged_in)
  {
   $data['main_content'] = 'home';
   $this->load->view('includes/template', $data);
  }
  else
  {
   $data['main_content'] = 'home';
   $this->load->view('includes/template', $data);
  }

}




Theme © iAndrew 2016 - Forum software by © MyBB