arrays - How to Display the first 20 messages in the DB -
i found code in internet, functions message box. code works fine. however, display messages stored in file message.db.
my question is, how can make display last 20 posted messages? i'm sorry asking this. have no knowledge programming. appreciate help...
here snippet of code:
<div class="container" ng-controller="messageboardctrl"> <form> <input type="email" placeholder="email address" ng-model="email" required/> <textarea placeholder="advertise link here free..." rows="5" style="width:90%" ng-model="message" required=""></textarea> <button class="btn btn-primary" ng-click="sendmessage()">post</button> </form> <p>{{item.message}}</p> <script> function messageboardctrl($scope, $http, $timeout) { $scope.items = []; $scope.message = ''; $scope.email = ''; $scope.lasttime = 0; $scope.refreshmessages = function() { $http.get('../templates/faucet.php/messages?time=' + $scope.lasttime).success(function(data) { for(id in data) { item = data[id]; $scope.items.unshift(item); if($scope.lasttime<item.time) $scope.lasttime = item.time; } }); } $scope.sendmessage = function() { if(!$scope.message) return; $http.post('../templates/faucet.php/add_message', {message: $scope.message, email: $scope.email}).success(function() { $scope.message = ''; $scope.refreshmessages(); }); } $scope.periodicrefresh = function() { $scope.refreshmessages(); $timeout($scope.periodicrefresh, 5000, true); } $scope.periodicrefresh(); } </script>
i found function limit result:
function limittofilter(){ return function(array, limit) { if (!(array instanceof array)) return array; limit = int(limit); var out = [], i, n; // check array iterable if (!array || !(array instanceof array)) return out; // if abs(limit) exceeds maximum length, trim if (limit > array.length) limit = array.length; else if (limit < -array.length) limit = -array.length; if (limit > 0) { = 0; n = limit; } else { = array.length + limit; n = array.length; } (; i<n; i++) { out.push(array[i]); } return out;
} }
now, need on how combine them make script work. hope can help. not have idea... thanks.
Comments
Post a Comment