Welcome Guest, Not a member yet? Register   Sign In
Building next/prev links
#4

[eluser]Sarfaraz Momin[/eluser]
Well I do have a similar implementation on few of my sites. The code goes as follows.

model
Code:
function get_prevnext_content($catid,$id,$prevnext){
    $this->db->select('content_id, content_name');
    $this->db->where('content_trash', 0);
    $this->db->where('subcategory_id', $catid);
    if($prevnext == 'prev'){
        $this->db->where('content_id <', $id);
        $this->db->orderby("content_id", "desc");
    }else {
        $this->db->where('content_id >', $id);
        $this->db->orderby("content_id", "asc");
    }
    $this->db->limit(1, 0);
    $result = $this->db->get('content');
    return $result->result();
}

the code for controller
Code:
$prevdata = $this->MyModel->get_prevnext_content($pull_content[0]->subcategory_id,$pull_content[0]->content_id,'prev');
        $nextdata = $this->MyModel->get_prevnext_content($pull_content[0]->subcategory_id,$pull_content[0]->content_id,'next');
        $prevlink = "<div style=\"float:left;width:380px;padding-left:10px\" align=\"left\"></div>";
        $nextlink = "<div style=\"float:left;width:380px;padding-left:10px\" align=\"left\"></div>";
        if($prevdata){
            $prevlink = "<div style=\"float:left;width:380px;padding-left:10px\" align=\"left\"><a title=\"".$prevdata[0]->content_name."\" href=\"".str_replace(" ","-",strtolower($prevdata[0]->content_name)).".html\" class=\"prevnext\">Previous Ecard</a></div>";
        }
        if($nextdata){
            $nextlink = "<div style=\"float:left;width:380px;padding-right:10px\" align=\"right\"><a title=\"".$nextdata[0]->content_name."\" href=\"".str_replace(" ","-",strtolower($nextdata[0]->content_name)).".html\" class=\"prevnext\">Next Ecard</a></div>";
        }

I hope this make some sense. Well this is quite simple. You get the id of the content and for next you just check the next id and for prev you just check prev id but just keep in mind to order the content properly or the results would not be good.

Good Day !!!


Messages In This Thread
Building next/prev links - by El Forum - 12-24-2007, 04:40 AM
Building next/prev links - by El Forum - 12-24-2007, 05:08 AM
Building next/prev links - by El Forum - 12-24-2007, 05:26 AM
Building next/prev links - by El Forum - 12-24-2007, 05:34 AM
Building next/prev links - by El Forum - 12-27-2007, 02:22 AM
Building next/prev links - by El Forum - 12-28-2007, 11:09 PM
Building next/prev links - by El Forum - 12-29-2007, 12:12 AM
Building next/prev links - by El Forum - 12-29-2007, 03:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB