I have a while loop fetching data from mysql database and I need to have them save in an html table format which works as per the below code. However instead of 'echoing' the table rows, is there a way to store the final table with all data in a single variable $finalTable so this way i can just echo $finalTable on any pages I need instead of writing the whole while loop each time:
echo '<table>';
while ($row = mysqli_fetch_assoc($resultX)){
$page_name = $row['page_name'];
$status = $row['status'];
echo '<tr>';
echo '<td>'.$page_name .'</td>';
echo '<td>'.$status.'</td>';
echo '</tr>';
}
echo '</table>';