• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination + URI Routing problem

#1
[eluser]mo2men[/eluser]
hi

this my code

routes.php
Code:
$routes['review/(:any)'] = "review/index/$1";

review.php
Code:
<?php
class review extends Controller{

   function _remap($method)
   {
      if(method_exists($this,$method))
      {
        $this->$method();
      }
      else
      {
        $this->index();
      }
   }

   function  __construct() {
       parent::Controller();
        $this->load->model('review_model');
        $this->load->library('form_validation');
        $this->load->library('pagination');
    }

    function index($offset='')
    {
       $url = $this->uri->segment(2);
       $query = $this->review_model->exist_review($url);
               if($query == FALSE){
                   echo "no";
               }


               else{
                $limit = 3;
                $total = $this->review_model->count_posts($url);
                
                $query = $this->review_model->read($limit,$offset);
                if($query)
                {
                $data['row'] = $query;
                }

                $config['base_url'] = base_url().'review/'.$url;
                $config['total_rows'] = $total;
                $config['per_page'] = $limit;
                $config['num_links'] = 3;
                $config['uri_segment'] = 3;
                
        $this->pagination->initialize($config);

        $data['pag_links'] = $this->pagination->create_links();
                $data['sidebar'] = 'review-sidebar';
                $data['site_content'] = 'review';
                $this->load->view('include/template.php',$data);

               }
    }

    
}
?>


review_model
Code:
<?php
class review_model extends Model{
    function  __construct() {
        parent::Model();
    }
    function exist_review($url){
        $this->db->select('username');
        $this->db->where('username',$url);
        $this->db->from('users');
        $query = $this->db->get();
           if($query->num_rows > 0 ){
                 return TRUE;
             }
             else{
                 return FALSE;
             }
    }

    function count_posts($url,$gpt=''){
                $this->db->where('username',$url);
      
         return $this->db->count_all_results('gpt');
     }

    function read($limit, $offset,$gpt=''){

     ($gpt) ? $this->db->where('gpt' , $gpt) : '';
     $this->db->limit($limit, $offset);
     $this->db->select('*');
     $this->db->from('gpt');
     $this->db->order_by('id','desc');
     $query = $this->db->get();
           if($query->num_rows > 0 ){
                 return $query->result();
             }
             else{
                 return FALSE;
             }

     }
    

}


?>

now i use Pagination and $routes['review/(:any)']

and when go http://localhost/site/review/mo2men/3

mo2men = $url

no get next records(data) from mysql

i don't know problem with mysql (model) or bath

help????????????

#2
[eluser]SPeed_FANat1c[/eluser]
here you need some debugging. You mean function read($limit, $offset,$gpt='') doesn't return results? Then try echo $limit, $offset,$gpt='' in this function and see if they are correct. And so on.

#3
[eluser]mo2men[/eluser]
ok
i try

i have error with $offset

$offset don't echo
it is NULL
Howi fix this ?

#4
[eluser]Gerep[/eluser]
Well, I'm new to it but I think in the review/index the line
Code:
$query = $this->review_model->read($limit,$offset);

I read your code and have not found any line where you give the variable $offset any value, try to check that.

Hope it really helps =)

#5
[eluser]InsiteFX[/eluser]
Also this.
Code:
$routes['review/(:any)'] = "review/index/$1";

Should be like this.
Code:
$routes['review/:any'] = "review/index/$1";

InsiteFX

#6
[eluser]mobilizedesign[/eluser]
isn't the class name supposed to be capitalized?

Code:
<?php
class Review extends Controller{
...

#7
[eluser]selinan[/eluser]
did you call the wrong object?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.