doudi4014 2017-02-22 08:40
浏览 61

填充下拉菜单,我的数据库中的数据始终为空

I am trying to fill dropdown menu with my data from database. But I have empty fields without any data and without errors in console. What am I droing wrong?

I am sending data as json and get it in angularjs.

There is my DB file in php. ( name = usersDB.php )

<?php 
$con = mysqli_connect("localhost", "root", "password", "db");

if(!$con){
    die('something wrong '.mysqli_error());
}

//echo ('test' . $_GET['action']);
switch($_GET['action'])  {
    case 'get_Logins_info' :
        get_Logins_info(); 
        break;

}

function get_Logins_info(){
    $qry = mysqli_query('SELECT * from login');

    echo("test");

    $data = array();
    while($rows = mysqli_fetch_array($qry))
    {
        $data[] = array(
                    "id"    => $rows['id'],
                    "name"      => $rows['name']
                    );
    }

    print_r(json_encode($data));
    return json_encode($data);
}

?>

My table login looks like:

id name username password

Angular part

        $scope.getLogins = function() {
            $http.get('forms/usersDB.php?action=get_Logins_info')
                .then(function(data, status, headers, config) {
                    $scope.chooseLogins = data;
                    console.log('Retrieved data from server');
                    console.log(data);
                })
                .then(function(data, status, headers, config) {
                    console.log("Error in retrieving data from server");
                    console.log(data, status);
                });
        };

        $scope.getLogins();

html

                <md-select ng-model="login" >
                    <md-option ng-repeat="logins in chooseLogins" ng-value="logins.id">{{logins.name}}</md-option>
                 </md-select>

I have dropdown list but is empty.

What console say?

Retrieved data from server
(index):118 Object {data: "test[]", status: 200, config: Object, statusText: "OK"}config: Objectdata: "test[]"headers: (name)status: 200statusText: "OK"__proto__: Object
(index):122 Error in retrieving data from server
(index):123 undefined undefined

Everything looks ok no errors but is empty.

  • 写回答

2条回答 默认 最新

  • douwen1901 2017-02-22 09:06
    关注

    The problem is that you aren't passing the database connection on this line:

    $qry = mysqli_query('SELECT * from login');
    

    Change it to:

    $qry = mysqli_query($con, 'SELECT * from login'); 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改