for number on huge number

PHP

$SCode=$_POST['SCode'];
$ECode=$_POST['ECode'];

for($p=$SCode;$p<$ECode;$p++)
{
    $dbResult= $dbHandle->query("
    SELECT Code
    FROM Mashaghel 
    Where Code=" . $p . "");
    if(!isset($Mashaghel[0]["Code"]) || empty($Mashaghel[0]["Code"]))
    {
        $errorCode.=$p."،";
    }
}
echo $errorCode."does not existed!";

i run this with

$_POST['SCode']='010100100101002084';
$_POST['ECode']='010100100101002087';

but this does not worked and say error Maximum execution time of 60 seconds exceeded While The difference between 010100100101002084 and 010100100101002087 only 3.

why for loop do infinite!?

please help me

Try this

for($p=0;$p<bcsub($ECode,$SCode);$p++)
    {
        $dbResult= $dbHandle->query("SELECT Code FROM Mashaghel
Where Code=" . bcadd($SCode,$p) . "");
        if(!isset($Mashaghel[0]["Code"]) || empty($Mashaghel[0]["Code"]))
        {
            $errorCode.=bcadd($SCode,$p)."،";
        }
    }

The reason your script is executing so long might be the query inside your loop. You could try to add 'LIMIT 1' to your query so it only processes one row or change 1 to the number of rows you need to process. If you still want to make your script be able to execute longer here's more info about it. By default, PHP terminates the script after 60 seconds to prevent scripts from hanging. There is a value in php.ini defining maximum time PHP script can run - it's called max_execution_time. You can also change this value for particular script by running set_time_limit() function (docs).

Change

 for($p=$SCode;$p<$ECode;$p++)

to

for($p=0; $p < ($ECode - $SCode - 1); $p++)

And references to $p inside the loop to $p+$SCode

break the limit of for into two numbers . for example think that your for loop limit number is 1000 break it to 100,10 make 2 nested for loops .

and for some numbers which are not dividable you can do some for loops one after another for example think that your number is 11 do it 5+6 like you have 2 for loops run exactly after each other with exact code in loop. also you can test while loop.

after all I don't think it's a solution it is just a way you can solve your problem temporary.