Last active
March 2, 2020 09:57
-
-
Save ronbeltran/7701123 to your computer and use it in GitHub Desktop.
Need to optimize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CS2 = mysql_query("SELECT VID, AN FROM Cl WHERE VID = '$VID' "); | |
while( $row = mysql_fetch_array($CS2) ) { | |
$AN1 = $row['AN']; | |
$VID = $row['VID']; | |
$BA = 0; | |
$PA = 0; | |
$TB = 0; | |
$Ba = 0; | |
$PHBSelect2 = mysql_query("SELECT AN, BD, BC, SUM(Amt) | |
FROM BHis | |
WHERE AN = '$AN1' | |
AND BD <= '$LockDate' | |
AND BC = 'P' | |
GROUP BY AN"); | |
while($row = mysql_fetch_array($PHBSelect2)) { | |
$PA = $row['SUM(Amt)']; | |
} | |
$BHBSelect2 = mysql_query("SELECT AN, BD, BC, SUM(Amt) | |
FROM BHis | |
WHERE AN = '$AN1' | |
AND BD <= '$LockDate' | |
AND BC = 'B' | |
GROUP BY AN"); | |
while($row = mysql_fetch_array($BHBSelect2)) { | |
$BA = $row['SUM(Amt)']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking at the two queries above $PHBSelect2 and $BHBSelect2 is almost the same so no need to have two separate query. Integrate the two query into one and do something with the result. It will reduce the time to fetch results from the DB especially if you have millions of records.