Blog
The Antropy OpenCart Blog
Handy PHP Snippets
PHP returns a special datatype for queries that can be converted in to an assoc. array of assoc. arrays with this:
$rows = array(); while($rows[] = mysqli_fetch_assoc($result)); array_pop($rows);
Display a query from the above as an HTML table:
$query = $your_query;
echo '<table border="1">';
echo '<tr>';
foreach($query[0] as $key => $value) {
echo '<td>';
echo $key;
echo '</td>';
}
echo '</tr>';
foreach($query as $row) {
echo '<tr>';
foreach($row as $column) {
echo '<td>';
echo $column;
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
Get the last second and first second of any given month:
$timestamp = strtotime('last month');
$first_second_last_month = strtotime(date('Y-m-01 00:00:00', $timestamp));
$last_second_last_month = strtotime(date('Y-m-t 23:59:59', $timestamp));
Flush to Browser
function flush_to_browser() {
echo str_repeat(' ', 4096);
flush();
}
More to come ...