I am sorry for the simple request, but I'm trying to figure out the best way to optimizing the following bit of code. I hate using 20 lines of code when 12-15 will suffice. I also don't like having to use intermediate variables if I don't need to.
$total_query_raw = "SELECT SUM( total ) AS total
FROM `tblinvoices`
WHERE `datepaid`
BETWEEN '$start_date 00:00:00' AND '$end_date 23:59:59'";
$total_query = mysqli_query($link, $total_query_raw);
if (!$total_query) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysqli_error();
exit;
}
$total_result = mysqli_fetch_array($total_query);
$grand_total = $total_result['total'];
echo "Grand Total: $" . number_format($grand_total,2) . "<br>";
mysqli_free_result($total_query);
Thanks in advance!