You can't loop over the column result-set multiple times. That code will work for the first data row, but then return false for every other data row because you've already reached the end of the column result set.
You should fetch that column data into an array before hand then loop over that array.
function getLuTableBody($lu_tableName) {
$tableColumns=getTableColumns($lu_tableName);
$columns = [];
while ($columnData = $tableColumns->fetch_assoc()){
$columns[] = $columnData['COLUMN_NAME'];
}
//Might as well check for 0 columns and bail early.
if (!$columns){
echo "problem with column data";
return;
}
$tableBodyHtml ="";
$tableData=getTableData($lu_tableName);
if ($tableData->num_rows > 0) {
while($row = $tableData->fetch_assoc()) {
foreach ($columns as $columnName){
$tableBodyHtml .= "<td>$row[$columnName]</td>";
}
}
} else {
echo "problem with record data";
}
return $tableBodyHtml;
}
You're also missing your <tr> </tr> tags for each row, and you shouldn't be echo'ing stuff if you find a problem. Throw an exception or return false or something.