我用angular和php建立一个项目,我可以注册一个新的"客户"并显示所有客户的详细信息,但我无法显示数据库中的特定行。有人可以帮忙吗?谢谢
customerCardDetailsCtrl.js - 获取特定客户的控制器
"use strict";
angular.module('dataSystem').
controller('customerCardDetailsCtrl', function($scope, $http ,$routeParams, $location) {
var customer_id = $routeParams.customer_id;
$scope.customer_id = customer_id;
var data = $.param({
customer_id: customer_id
});
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('api/readCustomer.php/' +customer_id,data,config ).
success(function(data){
$scope.customerDetails = data;
}).
error (function (error) {
colsole.log(error);
});
});
app.js - 特定路线
.when('/customerCardDetails/:customer_id', {
controller: "customerCardDetailsCtrl",
templateUrl: '../hamatkin/Views/customerCardDetails.html',
screenTitle: "",
costumerHidden: false,
reportsHidden: true,
stockHidden: true,
isIncome_expensesHidden: true,
isNavTabHidden: false,
isFooterHidden: false,
ordersHidden: true
})
readCustomer.php - 获取特定客户的php代码
<?php header('Content-Type: text/html; charset=utf-8');
include_once 'Customer.php';
$con = mysqli_connect('localhost','root','','hamatkin');
mysqli_query($con,"SET character_set_client = utf8");
mysqli_query($con,"SET character_set_connection = utf8");
mysqli_query($con,"SET character_set_results = utf8");
$customer = new Customer();
$query = "SELECT customer_id, kind_Of_Customer, full_name, id, city, address,phone,phone_2 FROM customers where customer_id= 82";
$result = $con->query($query);
$row = $result->fetch_assoc();
// reset the result resource
// mysql_data_seek($result, 0);
if( $result->num_rows!=0)
{
$customer->kind_Of_Customer = $row['kind_Of_Customer'];
$customer->full_name =$row['full_name'];
$customer->id = $row['id'];
$customer->city = $row['city'];
$customer->address = $row['address'];
$customer->phone = $row['phone'];
$customer->phone_2 = $row['phone_2'];
}
echo '<pre>'; print_r($customer); die;
$res = json_encode($customer);
echo $res;
?>
CustomerCardDetails.html - 用于显示特定客户的html页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div class="customerDetail">
<h1>כרטיס לקוח</h1>
<a href="/hamatkin/index.html#/customerCards">חזור לרשימת כרטיסי הלקוחות</a>
<div class="specific" >
customer id: {{customerDetails.customer_id}}</br>
customer full name: {{customerDetails.full_name}}
</div>
</div>
</body>
</html>