mysql - Getting multi rows in the table even if my database has no value using angular.js and PHP -
i have 1 problem in angular.js code.i have table filled database value. when database has no value , table should display blank in case database empty still table splitting 5 rows has no value.i explaining code below.
subject.html:
<table class="table table-bordered table-striped table-hover" id="datatable"> <colgroup> <col class="col-md-1 col-sm-1"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-2 col-sm-2"> <col class="col-md-1 col-sm-1"> </colgroup> <thead> <tr> <th>sl. no</th> <th> <select style="width:100%; border:none; font-weight:bold;"> <option>course name</option> </select> </th> <th>semester</th> <th>subject name</th> <th>short name</th> <th>edit</th> </tr> </thead> <tbody id="detailsstockid"> <tr ng-repeat="sub in subjectdata" > <td>{{ $index+1 }}</td> <td>{{sub.course_name}}</td> <td>{{sub.semester}}</td> <td>{{sub.subject_name}}</td> <td >{{sub.short_name}}</td> <td> <a href=''> <input type='button' class='btn btn-xs btn-green' value='edit'> </a> </td> </tr> </tbody> </table>
subjectcontroller.js:
var subapp=angular.module('gofastohome'); subapp.controller('subjectcontroller',function($scope,$http){ $http({ method: 'get', url: "php/subject/readsubjectdata.php", }).then(function successcallback(response) { console.log('response',response); $scope.subjectdata=angular.fromjson(response); },function errorcallback(response) { alert("could not fetch data"); }); })
here database has no value.when user refreshing(i.e-subject.html
) page table present in html content splitting 5 rows no data 5 serial number coming don't need.check php file below.
readsubjectdata.php:
$connect = mysqli_connect("localhost", "root", "******", "go_fasto"); $result = mysqli_query($connect, "select * db_subject order subject_id desc "); $data = array(); while ($row = mysqli_fetch_assoc($result)) { $data[] = $row; } print json_encode($data);
my requirement table splitted when database has value.when data database blank should not getting in current code.please me.
try this:
add script
ng-show="showtable"
table tag become this:<table ng-show="showtable" class="table table-bordered table-striped table-hover" id="datatable">
then change controller script below:
var subapp=angular.module('gofastohome'); subapp.controller('subjectcontroller',function($scope,$http){ $http({ method: 'get', url: "php/subject/readsubjectdata.php", }).then(function successcallback(response) { console.log('response',response); $scope.subjectdata=angular.fromjson(response); if($scope.subjectdata.length > 0) // $scope.showtable = true; // add these lines else // $scope.showtable = false; // },function errorcallback(response) { alert("could not fetch data"); }); })
Comments
Post a Comment