can';t使用angular和php使用下拉列表获取数据
我正在用angular和php构建一个项目。我的数据库中有一个“客户”表。我正在尝试从下拉列表中的“Customers”表中获取所有名称,但它不起作用。控制台目前没有显示任何错误。有人能查一下我的密码吗 Html: Phpcan';t使用angular和php使用下拉列表获取数据,php,angularjs,Php,Angularjs,我正在用angular和php构建一个项目。我的数据库中有一个“客户”表。我正在尝试从下拉列表中的“Customers”表中获取所有名称,但它不起作用。控制台目前没有显示任何错误。有人能查一下我的密码吗 Html: Php 您应该获得响应。数据,而不仅仅是响应,如下所示: $scope.customersDetails = response.data; 另外,我建议您使用而不是ngRepeat指令。您应该获得响应。数据而不仅仅是响应,如下所示: $scope.customersDetails
您应该获得
响应。数据
,而不仅仅是响应
,如下所示:
$scope.customersDetails = response.data;
另外,我建议您使用而不是
ngRepeat
指令。您应该获得响应。数据
而不仅仅是响应
,如下所示:
$scope.customersDetails = response.data;
另外,我建议您使用而不是
ngRepeat
指令。您的PHP文件有一些问题
1-没有客户类别。(我想这个例子你不需要)
2-$queryResult2=array();您创建了一个数组,但没有提供数据
3-您对空数组进行了编码
4-您尝试对已编码的数据进行编码
请检查固定示例:
<?php
header('Content-Type: text/html; charset=utf-8');
$connection = mysqli_connect('localhost','root','','hamatkin');
mysqli_query($connection,"SET character_set_client = utf8");
mysqli_query($connection,"SET character_set_connection = utf8");
mysqli_query($connection,"SET character_set_results = utf8");
if(!$connection){
die("couldnt connect".mysqli_error);
}
/*
I dont know if you have 'Customer' class
*/
// $customer = new Customer();
// $query = "SELECT * FROM `customers`";
$query = "SELECT customer_id, full_name FROM `customers`";
$queryResult = $connection->query($query);
$queryResult2 = array();
if( $queryResult->num_rows>0){
$i = 0;
while($row = $queryResult->fetch_assoc()){
// if you dont have Customer class, there is no $customer->....
// $customer->customer_id = $row['customer_id']
// $customer->full_name =$row['full_name']
// put the data in $queryResult2
// $queryResult2[$i]['customer_id'] = $row['customer_id'];
// $queryResult2[$i]['full_name'] = $row['full_name'];
// OR
$queryResult2[] = $row;
$i++;
}
}
header('Content-type:application/json');
$queryResult3 = json_encode($queryResult2);
// echo json_encode($queryResult3); // you don't need to encode again.
echo $queryResult3;
?>
您的PHP文件有一些问题
1-没有客户类别。(我想这个例子你不需要)
2-$queryResult2=array();您创建了一个数组,但没有提供数据
3-您对空数组进行了编码
4-您尝试对已编码的数据进行编码
请检查固定示例:
<?php
header('Content-Type: text/html; charset=utf-8');
$connection = mysqli_connect('localhost','root','','hamatkin');
mysqli_query($connection,"SET character_set_client = utf8");
mysqli_query($connection,"SET character_set_connection = utf8");
mysqli_query($connection,"SET character_set_results = utf8");
if(!$connection){
die("couldnt connect".mysqli_error);
}
/*
I dont know if you have 'Customer' class
*/
// $customer = new Customer();
// $query = "SELECT * FROM `customers`";
$query = "SELECT customer_id, full_name FROM `customers`";
$queryResult = $connection->query($query);
$queryResult2 = array();
if( $queryResult->num_rows>0){
$i = 0;
while($row = $queryResult->fetch_assoc()){
// if you dont have Customer class, there is no $customer->....
// $customer->customer_id = $row['customer_id']
// $customer->full_name =$row['full_name']
// put the data in $queryResult2
// $queryResult2[$i]['customer_id'] = $row['customer_id'];
// $queryResult2[$i]['full_name'] = $row['full_name'];
// OR
$queryResult2[] = $row;
$i++;
}
}
header('Content-type:application/json');
$queryResult3 = json_encode($queryResult2);
// echo json_encode($queryResult3); // you don't need to encode again.
echo $queryResult3;
?>
问题出在php代码$queryResult2=array()中;那么?@B.Kocaman很抱歉,我是新手,我该怎么办?问题在于您的php代码$queryResult2=array();那么?@B.Kocaman对不起,我是新手,我该怎么办?
<?php
header('Content-Type: text/html; charset=utf-8');
$connection = mysqli_connect('localhost','root','','hamatkin');
mysqli_query($connection,"SET character_set_client = utf8");
mysqli_query($connection,"SET character_set_connection = utf8");
mysqli_query($connection,"SET character_set_results = utf8");
if(!$connection){
die("couldnt connect".mysqli_error);
}
/*
I dont know if you have 'Customer' class
*/
// $customer = new Customer();
// $query = "SELECT * FROM `customers`";
$query = "SELECT customer_id, full_name FROM `customers`";
$queryResult = $connection->query($query);
$queryResult2 = array();
if( $queryResult->num_rows>0){
$i = 0;
while($row = $queryResult->fetch_assoc()){
// if you dont have Customer class, there is no $customer->....
// $customer->customer_id = $row['customer_id']
// $customer->full_name =$row['full_name']
// put the data in $queryResult2
// $queryResult2[$i]['customer_id'] = $row['customer_id'];
// $queryResult2[$i]['full_name'] = $row['full_name'];
// OR
$queryResult2[] = $row;
$i++;
}
}
header('Content-type:application/json');
$queryResult3 = json_encode($queryResult2);
// echo json_encode($queryResult3); // you don't need to encode again.
echo $queryResult3;
?>