php - fetch data from database using angularjs using where clause -
i want load data mysql database using angularjs.
this how application works; users login , username stored in cookie. username displayed on home page
i want value , pass php script through angularjs fetch data table based on username clause
this php scrip
<?php include_once 'connect.php'; $data = json_decode(file_get_contents("php://input")); $statement = $conn->prepare('select messageid, subject, messagecontent, concat(date, " , ", time) date, fromuser, touser, messagetype, file, filename messages messagetype = "broadcast" or touser=:username order messageid desc'); $statement->execute(array( 'username' => $data->usercookie )); while($row = $statement->fetch()) { $data[] = $row; } print json_encode($data); ?>
this angular script
var app = angular.module('library', ["ngcookies"]); app.controller('librarycontroller', function($scope, $http, $interval, $cookies) { //get cookie user name $scope.usercookie = $cookies.get('cookieusername'); //set cookie user name $scope.setcookie = function(val){ $cookies.put('cookieusername', val); } //display messages $scope.loadmessages = function() { $http.post('selectmessages.php',{'username': $scope.usercookie}) .success(function(data) { $scope.messages = data; }) } //display messages @ interval of 1 seconds $interval($scope.loadmessages, 1000); });
this home page
<!doctype html ng-app="library" ng-controller="librarycontroller"> <html> <head> <title></title> </head> <body ng-init="loadmessages()"> <div class="form-group"> <label for="subject">user</label> <input type="text" ng-model="usercookie" name="usercookie" class="form-control" id="usercookie" required="required"></input> </div> <input type="search" class="form-control" ng-model="searchmessage" placeholder="search"> <br /> <table class="table table-hover"> <thead> <tr> <th>message (sender)</th> </tr> </thead> <tbody> <tr ng-click="selectmessage(message.messageid, message.messagecontent, message.date, message.time, message.file)" onclick="showcommentdialog()" style="font-size: 16px" ng-repeat="message in messages | filter:searchmessage | limitto:20"> <td>{{ message.subject }} (<span style="color:green"> {{ message.fromuser }})</span></td> <td> <button class="btn btn-success" ng-click="selectmessage(message.messageid, message.messagecontent, message.date, message.time, message.file)" onclick="showcommentdialog()" > view </button> </td> </tr> </tbody> </table> </body> </html>
this error geterror browser console please have done wrong. help!
see this link help. have duplicates keys in ng-repeat.
Comments
Post a Comment