sách gpt4 ai đã đi

Lấy dữ liệu từ cơ sở dữ liệu bằng cách sử dụng mệnh đề where sử dụng angularjs

In lại 作者:行者123 更新时间:2023-11-29 20:01:20 26 4
mua khóa gpt4 Nike

我想使用 angularjs 从 mysql 数据库加载数据。

这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上

我想获取这个值并通过 angularjs 传递给 php 脚本,以便根据带有 where 子句的用户名从表中获取数据

这是我的 php 脚本


include_once 'connect.php';
$data = json_decode(file_get_contents("php://input"));


$statement = $conn->prepare('SELECT MessageId, Subject, MessageContent, CONCAT(Date, " , ", Time) AS Date, FromUser, ToUser, MessageType, File, FileName FROM messages where MessageType = "Broadcast" or ToUser=:UserName order by MessageId desc');
$statement->execute(array(
'UserName' => $data->UserCookie
));

while($row = $statement->fetch()) {
$data[] = $row;
}

print json_encode($data);
?>

这是我的 Angular 脚本

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 at an interval of 1 seconds
$interval($scope.loadMessages, 1000);

});

这是我的主页



<đầu>



























Message (Sender)
{{ message.Subject }} ( {{ message.FromUser }})



这是我得到的错误 Error from browser console请问我做错了什么。帮忙!

1 Câu trả lời

Xem thêmthis link求助。您的 ng-repeat 中有重复的键。

关于php - 使用 angularjs 使用 where 子句从数据库获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40528061/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com