Ok, for all you cringers out there who hate messy code.. and that includes me... I cleaned it up a little
function Scan_DB($trtN, $trtS, $trtE, $trtW, $N, $S, $E, $W, $TenTimes, &$Resolution)
{
$trQ = sprintf("SELECT count(*) FROM TileRegionTable WHERE North<=%f and South>=%f and East<=%f and West>=%f and East>West",
$trtN, $trtS, $trtE, $trtW);
$trRes = mysql_query($trQ,$_SESSION['trDB']->link);
$Error = mysql_error();
$trRow = mysql_fetch_array($trRes);
$trCount = $trRow[0];
$trQ = sprintf("SELECT * FROM TileRegionTable WHERE North<=%f and South>=%f and East<=%f and West>=%f and East>West",
$trtN, $trtS, $trtE, $trtW);
$trRes = mysql_query($trQ,$_SESSION['trDB']->link);
$Error = mysql_error();
if ($Error) echo "Error :1: $Error<br>";
else
{
$trRow = mysql_fetch_array($trRes, MYSQL_ASSOC);
$Error = mysql_error();
if ($Error) echo "Error :2: $Error<br>";
else
{
if ( $trRow != NULL )
{
$NextHighRes = 0;
$CheckThisDB = Make_Table_Name($trRow['North'], $trRow['South'], $trRow['East'], $trRow['West']);
// Get the next resolution down in our list of resolutions
$AnyImagesQ = sprintf("SELECT * FROM %s WHERE North<=%f and South>=%f and East<=%f and West>=%f and East>West and round((Resolution*%d))<%10.2f ORDER BY Resolution DESC",
$CheckThisDB, $N, $S, $E, $W, $TenTimes, $Resolution*$TenTimes);
$AIResult = mysql_query($AnyImagesQ,$_SESSION['AIdb']->link);
echo "1<br>";
$AIRow = mysql_fetch_array($AIResult);
echo "2<br>";
// Reset to the new higher resolution if it is the highest so far
if ( (!empty($AIRow)) && ($AIRow != NULL) )
{
echo "3<br>";
$NextHighRes = (($AIRow['Resolution'] > $NextHighRes) ? $AIRow['Resolution'] : $NextHighRes);
echo "4<br>";
Store_Session_Var($NextHighRes, "Resolution");
echo "5<br>";
}
echo "6<br>";
$trRow = mysql_fetch_array($trRes, MYSQL_ASSOC);
echo "7<br>";
$Error = mysql_error();
if ($Error) echo "ERROR fetch :: $Error<br>";
if ( $trRow != NULL )
{
echo "There is data<br>";
$OuttaHere = 0;
}
echo "8<br>";
if ( $trRow == NULL )
{
echo "There is no more data<br>";
$OuttaHere = 1;
}
echo "9 :: OuttaHere = $OuttaHere<br>";
echo "<br><br>Out Of LOOP<br><br>";
$Resolution = $NextHighRes;
// We need this to check the smaller resolutions < 1 for some weird reason. I have no clue why
if ( $Resolution < 1 )
{
$TenTimes = 1;
$ResTemp = $Resolution;
do
{
$TenTimes *= 10;
$ResTemp = $Resolution * $TenTimes;
} while ( $ResTemp < 1 );
$CIBData = 1;
Store_Session_Var($CIBData, "CIBData"); if ( $_SESSION['Debug'] > $DebugThreshold ) echo "ssv-cibdata 3<br>";
}
else { $TenTimes = 1.0; $CIBData = 0; Store_Session_Var($CIBData, "CIBData"); if ( $_SESSION['Debug'] > $DebugThreshold ) echo "ssv-cibdata 4<br>";}
} // $trRow != NULL
} // e: Error 2 : fetch_array($trRes)
} // e: Error 1 : mysql_query($trQ)
/*---*/
echo "Out of SCAN_DB<br>"; ob_flush(); flush();
return(0);
}//Scan_DB
I stuck the echo numbers out to the margin so you all can see when I say it hits numbers x,y,z where numbers x,y,z are easily... do not hassle me on this point and tell me they shouldn't stick out... it's not going to help solve the problem and it certainly isn't the problem... thanks
When data is returned to AIRow, no problem. You see numbers 1 - 9 then Out Of LOOP.
When NULL is returned to AIRow, You only see numbers 1, 2, 6, 7, 8 and 9 but you never see Out Of LOOP....
this is the mystery....