I have this chunk of code which works on my local XAMPP testing server. The problem is, when pushed to the production server, it breaks. This isn't an issue with the database connection, and PHP/MySQL are both at 5.3 on the production server so it isn't the use of old versions of either. I'm thinking it's the use of the foreach loop instead of the more standard while loop; if it's that, why?
<?php
$res = $mysqli->query('DESCRIBE '.$table);
$columnCount = 0;
echo '<ul>';
foreach($res as $field) {
if(in_array($field["Field"], $sheetData[0])) {
echo '<li>';
//var_dump($field);
echo $field['Field'].' - '.$field['Type'];
echo "</li>\r\n";
$columnCount++;
}
}
echo '</ul>';
?>
EDIT: To clarify, it breaks by not outputting anything at all; when inserting a simple echo statement inside the loop, it seems to not even execute it.
EDIT2: I've added an answer below which goes into slightly more detail about what the problem here actually was and why this code does actually work under certain conditions.