Skip to main content
deleted 22 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Need Help Optimizinghelp optimizing PHP/MySQL Code Snippetcode snippet

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!

Need Help Optimizing PHP/MySQL Code Snippet

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!

Need help optimizing PHP/MySQL code snippet

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);
Source Link
Dizzy49
  • 199
  • 1
  • 5

Need Help Optimizing PHP/MySQL Code Snippet

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!