Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Hi iam trying to fetch the data from database using angularjs but it is not displaying any data.I just started to learn AngularJs.Can any one help me this.Here is my code

income.html

<div class="container jumbotron"  ng-init= "getIncomeSource()" ng-controller="IncomeSourcesController" id="homejumbotron">
<table>
    <thead>
        <th>Name of the Employer</th>
        <th>Income From Salary</th>
        <th>TDS Deducted</th>
        <th></th>
    </thead>
    <tbody>
        <tr ng-repeat="x in incomesources" >

    <td>{{x.company_name}}</td>
    <td>{{x.user_income}}</td>
    <td>{{x.tax_deducted_salary}}</td>


    </tbody>

js

var app = angular.module('accountantApp', []);
app.controller('IncomeSourcesController', function($scope,$http) {
console.log("inside homecontroller:::");    
$scope.getIncomeSource = function(){
$scope.user = "";
console.log("Inside getPersonalInfo::::::");    
$http({
        method  : 'POST',
         url        : '../model/incomesources.php',           
        headers : {
                    'Content-Type': 'application/json'
                  },
              data      : {"action": "GetIncomeSources"}
       })
       .success(function( data,status, headers) {
        console.log("Response data:"+ JSON.stringify(data));
        if (data.success != undefined && data.success != '')
        {
          $scope.user = data;
        }
        })
        .error(function(data, status, headers) {
        alert("Error occured while retrieving:"+status);
        console.log("Error data::::"+ data);
        console.log("status::::"+ status);
        });             
};  
});

incomesources.php

function getIncomeSources()
{
session_start();
 $userInfo = $_SESSION['USER'];
 $userEmailid= $userInfo-> getEmailid();
 $res="SELECT *  FROM user_salary_details  WHERE email ='$userEmailid'";
 $result=mysql_query($res);            
 if ($row = mysql_fetch_assoc($result))
  {
     $companyname  = $row["company_name"];
     $userincome = $row["user_income"];
     $employetype   = $row["employe_type"];
     $tan     = $row["tan_employer"];
     $tax = $row["tax_deducted_salary"];
     $address = $row["address"];
     $state = $row["state"];
     $city=$row["city"];
     $pin=$row["pincode"];
     $data = array(
                    "success"   =>  "success",
                "companyname"   =>  $companyname,
                    "userincome"    =>  $userincome,
                "employetype"   =>  $employetype,
                "tan"   =>  $tan,
                    "tax"   =>  $tax,
                    "address"    =>      $address,
                    "state"   =>      $state,
                     "city" =>$city,
                     "pin"=>$pin,
              );

     echo json_encode($data);         
     }else{
        echo "No record exists for this user::";            
     }   
}
share|improve this question
    
Here u need to add one more parameter data in success fn – Suresh B Feb 19 '16 at 7:05
    
which parameter i need to add – Nagu Feb 19 '16 at 7:07
    
.success(function( status, headers, data) { console.log("Response data:"+ JSON.stringify(data)); – Suresh B Feb 19 '16 at 7:09
    
console.log("Response data:"+ JSON.stringify(data) Here you used data but data is not defined anywhere – Suresh B Feb 19 '16 at 7:09
    
console what it shows? – Suresh B Feb 19 '16 at 7:10

Is your incomesources.php was working initially?

The WHERE clause in the select statement is looking for email='$userEmailid'

i think you want the content of $userEmailid. So try change to

$res="SELECT *  FROM user_salary_details  WHERE email ='". $userEmailid ."'";

EDIT Since your php file is working, and you mentioned in above comments that you are able to see the return value in console, lets see your html and js code.

In your html please change to

<tr ng-repeat="x in user" >

    <td>{{x.companyname}}</td>
    <td>{{x.userincome}}</td>
    <td>{{x.tax}}</td>

The properties in {{x.something}} is based on the php return properties, not from database column name.

In your js file, try initialize the $scope.user outside $scope.getIncomeSource function and init it as an array. For example

console.log("inside homecontroller:::");   

$scope.user = []; // this

$scope.getIncomeSource = function(){

console.log("Inside getPersonalInfo::::::");    
$http({

Hope this help

share|improve this answer
    
no it is working it is printing the data in console – Nagu Feb 19 '16 at 7:34
    
As i tried this also but it is not working – Nagu Feb 19 '16 at 10:06
    
Sorry, I thought the return from the php is an array. It just a json object. Can you please change the line to $scope.user = {}; – Popoi Menenet Feb 19 '16 at 10:25
    
No it is not working – Nagu Feb 19 '16 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.