It’s not displayed as table, because you don’t return correct HTML code. Let’s take a look at your code (I’ve put comments at end of incorrect lines):
$content="<table>";
$content .= '</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>'; // <- here you open TR with </tr>, so it's already incorrect
$results = $seconddb->get_results( ' SELECT * FROM seconddb_PontoonBoats_LineOne_2Log' );
foreach ( $results AS $row ) {
$content="<tr>"; // <- here you overwrite previous value of $content with string '<tr>'
// Modify these to match the database structure
$content .= '<td>' . $row->{'Week Beginning'} . '</td>';
$content .= '<td>' . $row->Monday . '</td>';
$content .= '<td>' . $row->Tuesday . '</td>';
$content .= '<td>' . $row->Wednesday . '</td>';
$content .= '<td>' . $row->Thursday . '</td>';
$content .= '<td>' . $row->Friday . '</td>';
$content .= '<td>' . $row->Saturday . '</td>';
$content .= '<td>' . $row->Sunday . '</td>';
$content .= '<td>' . $row->{'Weekly Total'} . '</td>';
$content .= '<td>' . $row->{'Previous Week Totals'} . '</td>';
$content .= '</tr>';
}
$content .= '</table>';
So your function returns something like this, if there are no rows (it’s incorrect HTML):
<table>
</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>
</table>
And something like this, if there are any rows found:
<tr>
<td><VALUE FOR: $row->{'Week Beginning'}></td>
<td><VALUE FOR: $row->Monday></td>
<td><VALUE FOR: $row->Tuesday></td>
<td><VALUE FOR: $row->Wednesday></td>
<td><VALUE FOR: $row->Thursday></td>
<td><VALUE FOR: $row->Friday></td>
<td><VALUE FOR: $row->Saturday></td>
<td><VALUE FOR: $row->Sunday></td>
<td><VALUE FOR: $row->{'Weekly Total'}></td>
<td><VALUE FOR: $row->{'Previous Week Totals'}></td>
</tr>
</table>
And here’s the fixed version of that function:
function pontoon_table_shortcode( $args ) {
global $seconddb;
// Shortcodes RETURN content, so store in a variable to return
$content="<table>";
$content .= '<tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previous Week Totals</th></tr>';
$results = $seconddb->get_results( ' SELECT * FROM seconddb_PontoonBoats_LineOne_2Log' );
foreach ( $results AS $row ) {
$content .= '<tr>';
// Modify these to match the database structure
$content .= '<td>' . $row->{'Week Beginning'} . '</td>';
$content .= '<td>' . $row->Monday . '</td>';
$content .= '<td>' . $row->Tuesday . '</td>';
$content .= '<td>' . $row->Wednesday . '</td>';
$content .= '<td>' . $row->Thursday . '</td>';
$content .= '<td>' . $row->Friday . '</td>';
$content .= '<td>' . $row->Saturday . '</td>';
$content .= '<td>' . $row->Sunday . '</td>';
$content .= '<td>' . $row->{'Weekly Total'} . '</td>';
$content .= '<td>' . $row->{'Previous Week Totals'} . '</td>';
$content .= '</tr>';
}
$content .= '</table>';
// return the table
return $content;
}