Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] twitter like pagination
#1

[eluser]arro[/eluser]
hii all, I wanna ask about paging like twitter style..
I have read -http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/- and try it, it's work..

this is my controller
Code:
function get_messages_people($id,$offset)
    {
        $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);
        $data['latest_comments'] = $this->people_model->get_comments_people();
        $this->load->view('people/get_messages_people', $data);
    }

this is my model
Code:
function get_messages_people($id,$offset=0){
        $this->db->select('*');
        $this->db->from('posts');
        $this->db->where('posts.receiper',$id);
        $this->db->limit(10,$offset);
        $query = $this->db->get();
        return $query->result();
    }

if I'm no using the $id, it's great work, but when use $id, this not work..
and I get error when I use $id -> Message: Undefined variable: offset
what the problem here?

thank you in advance....

[SOLVED]
thanks for this forum and who's help me to fix this problem..
especially thanks to Christian Gile.. Smile
#2

[eluser]InsiteFX[/eluser]
Please read the CodeIgniter User Guide on get_where!

CodeIgniter User Guide - Active Record Class - $this->db->get_where();

InsiteFX
#3

[eluser]arro[/eluser]
still got error in my controller -> $offset unidentified...
I didn't understand with many realtionship table.. Sad
how if I have this model to implement get_where?
Code:
function get_messages_people($id,$offset=0){
        $this->db->select('*,users.id_user as idus,votes.id_user as voter,posts.id_post as idp,votes.id_post as idpv,posts.content as isi');
        $this->db->from('users');
        $this->db->join('photos','users.id_user = photos.id_user and avatar != 0','left');
        $this->db->join('posts','users.id_user = posts.id_user and posts.category != "message"');
        $this->db->join('votes','posts.id_post = votes.id_post and votes.id_user = '.$this->session->userdata('id_user').'','left');
        $this->db->where('posts.receiper',$id);
        $this->db->limit(10,$offset);
        $this->db->group_by('posts.id_post');
        $this->db->order_by('posts.id_post','desc');
        $query = $this->db->get();
        return $query->result();
    }
#4

[eluser]InsiteFX[/eluser]
I do not have the time to write this for you, but the last two lines should be
like below for example

Code:
function get_messages_people($id, $limit = NULL, $offset = NULL)
{
    $query = $this->db->get_where('posts', array('id' => $id), $limit, $offset);
    return $query->result();
}

InsiteFX
#5

[eluser]arro[/eluser]
I still got error in my controller...

Code:
function get_messages_people($id,$offset)
    {
        $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);
        $data['latest_comments'] = $this->people_model->get_comments_people();
        $this->load->view('people/get_messages_people', $data);
    }

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: offset
Filename: controllers/people.php
Line Number: 88

I'm confused with how to declaration $offset in my controller??

thank you so much InsiteFX ...
#6

[eluser]Cristian Gilè[/eluser]
[quote author="arro" date="1295256323"]I still got error in my controller...

Code:
function get_messages_people($id,$offset)
    {
        $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);
        $data['latest_comments'] = $this->people_model->get_comments_people();
        $this->load->view('people/get_messages_people', $data);
    }

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: offset
Filename: controllers/people.php
Line Number: 88

I'm confused with how to declaration $offset in my controller??

thank you so much InsiteFX ...[/quote]

Do you pass the offset parameter to the controller get_messages_people function when you call it?

If it's an optional parametet set it to:
Code:
function get_messages_people($id,$offset = 0)
    {
        $data['latest_messages'] = $this->people_model->get_messages_people($id,$offset);
        $data['latest_comments'] = $this->people_model->get_comments_people();
        $this->load->view('people/get_messages_people', $data);
    }


Cristian Gilè
#7

[eluser]arro[/eluser]
thanks for the reply, Cristian Gilè, I have try before, the error was diseapear but not work too..
hmm..
this is in my view..
Code:
var num_messages = <?php echo $num_messages?>;
            var loaded_messages = 0;
            $("#more_button").click(function(){
                loaded_messages += 10;
                $.get("http://localhost/myweb/people/get_messages_people/" + loaded_messages, function(data){
                    $("#main_content").append(data);

                });

                if(loaded_messages >= num_messages - 10)
                {
                    $("#more_button").hide();
                    //alert('hide');
                }
            })
I dont know why if isset $id in my controller, it's not work?
any ideas or link how to make "more button" pagination?
I am very confused with this controller...
thanks before..
#8

[eluser]Cristian Gilè[/eluser]
[quote author="arro" date="1295368508"]thanks for the reply, Cristian Gilè, I have try before, the error was diseapear but not work too..
hmm..
this is in my view..
Code:
var num_messages = <?php echo $num_messages?>;
            var loaded_messages = 0;
            $("#more_button").click(function(){
                loaded_messages += 10;
                $.get("http://localhost/myweb/people/get_messages_people/" + loaded_messages, function(data){
                    $("#main_content").append(data);

                });

                if(loaded_messages >= num_messages - 10)
                {
                    $("#more_button").hide();
                    //alert('hide');
                }
            })
I dont know why if isset $id in my controller, it's not work?
any ideas or link how to make "more button" pagination?
I am very confused with this controller...
thanks before..[/quote]

get_messages_people requires two parameters, id and offset, so the get request in jquery should be like this.

Code:
$.get("http://localhost/myweb/people/get_messages_people/" + id + "/" + loaded_messages, function(data){
                    $("#main_content").append(data);

                });

Cristian Gilè
#9

[eluser]arro[/eluser]
this problem has solved..you are the man Cristian Gilè....
thank you so much for your help.. Smile




Theme © iAndrew 2016 - Forum software by © MyBB