i have one problem in my angular.js code.I have a table which will filled up by database value. when initially my database has no value and table should display blank but in my case now the database is empty still the table is splitting into 5 rows which has no value.I am explaining my 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 initially my database has no value.When user is refreshing(i.e-subject.html) the page the table present in the html content is splitting into 5 rows with no data but 5 serial number is coming which i don't need.check my php file below.
readSubjectData.php:
$connect = mysqli_connect("localhost", "root", "******", "go_fasto");
$result = mysqli_query($connect, "select * from db_subject order by subject_id desc ");
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
print json_encode($data);
My requirement is table will be splitted only when database has some value.When data database is blank it should not which i am getting in my current code.Please help me.