I am generating a dynamic table, from the databasw (SQL Server 2012) using php. Using the code pasted below :
<table class="table table-bordered" id="tb">
<tr style="BACKGROUND-COLOR: DarkGrey ">
<th colspan="4" style="text-align:Center;">Objectives and Targets </th>
</tr>
<tr class="tr-header">
<th>Objectives / Measures</th>
<th colspan="2">Targets / Achievements / Timelines</th>
<th style="text-align:Center;width:1%;" rowspan="2">Weightage %</th>
</tr>
<tr>
<th> </th>
<th> </th>
<th style="width:10%;"> Date </th>
</tr>
<tbody>
<?PHP
$myquery=" select replace(Objectives, '||<==', '') as Objectives, replace(Targets, '==', '') as Targets, replace(Weightage, '==', '') as Weightage, Corporate_Objective, Corporate_Objective_Weightage from Appraisal_Objectives WHERE Serial_Number='$Serial_Number' ORDER BY Row_Number asc";
$fetched=sqlsrv_query($conn,$myquery) ;
if( $fetched === false ) { die( print_r( sqlsrv_errors(), true ));}
while($res=sqlsrv_fetch_array($fetched,SQLSRV_FETCH_ASSOC))
{
$Corporate_Objective=$res['Corporate_Objective'];
$Weightage=$res['Weightage'];
$Objectives=$res['Objectives'];
$Targets=$res['Targets'];
$Corporate_Objective_Weightage=$res['Corporate_Objective_Weightage'];
echo "<tr><td>".$Corporate_Objective."</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td><b>".$Corporate_Objective_Weightage."</b></td></tr>";
echo "<tr><td>".$Objectives."</td>";
echo "<td>".$Targets."</td>";
echo "<td></td>";
echo "<td>".$Weightage."</td></tr>";
}
?>
</tbody>
</table>
Issue
The output is creating many unwanted, blank rows inbetween each row! I haven't added any <br/>
or and extra row in the code. Also, the rows in the databse do not have any spaces.
Where could I have gone wrong. Appreciate any help/suggestion. Thanks in advance.
ScreenShot of the dynamic table output
I changed my SQL Query and used COALESCE. The code is as below :
select Targets,target_date,ROW_NUMBER,
COALESCE(Corporate_Objective,Objectives) AS Objectives,
COALESCE(Corporate_Objective_Weightage,Weightage) AS Weightage
FROM Appraisal_Objectives WHERE Serial_Number like '%1153';
This removed all the spaces in the table :