Welcome Guest, Not a member yet? Register   Sign In
Tell me your Ideas (notification system)
#1

[eluser]Maiden13[/eluser]
Hey all, Im wondering what would be the best way for accessing notifications. What im wanting is on the main page there is a box with a summery of the 5 latest notifications, then when you click on "view more" it takes you to a page with all the current notifications.

How would I go about this? Have a controller that accesses the model to retrieve all notifications then sends all to the view, then on the main page have the controller access the latest 5 from the view that has all notifications?

Or Have two models, one dealing with getting the latest 5 while the other retrieves all notifications?

Let me know what you would do. I would be really interested in any ideas you have also Smile

Thanks.
#2

[eluser]Bastian Heist[/eluser]
Have one model with one get function that takes a parameter that allows you to set a limit.
in the controller of the main page, request it with that parameter set to five, in the other, request it with how many notifications you want displayed (and pagination options, probably).
#3

[eluser]munkeh[/eluser]
Something like this?

Code:
function get_notification($some_index, $num_results=NULL) {

    $this->db->select('whatever','data','you','need');
    $this->db->from('notification_table');
    $this->db->where('index', $some_index);
    $this->db->order_by('id', "desc");
    
    if (isset($num_results)) {$this->db->limit($num_results);}
    
    $query = $this->db->get();
    $num_rows = $query->num_rows();
    
    if ($num_rows == 0)
    {
        return FALSE;
    } else
    {
        return $query->result_array();
    }

}

then get_notification($some_index, 3) gives you the latest 3 items assuming your 'id' field auto increments. get_notification($some_index) will give you all of them.
#4

[eluser]Maiden13[/eluser]
Thanks munkeh, That is perfect!




Theme © iAndrew 2016 - Forum software by © MyBB