Hi!

I wonder if I can optimize following code (or do something better) below?
It works fine when about 3.000 rows exists in the textfile, but when it gets
to 10.000 rows then it will get a session timeout. (or internal server
error)


<?php

function checkSaldo($url, $articleNrFieldNr, $saldoFieldNr, $separator,
$startLine, $prefix) {

require ("phpfunctions/opendb.php");

//Read in specified file into array
//
$fileArray = file($url);

//Go through array
//
for ($i=$startLine;$i<count($fileArray);$i++) {

        //Get line of file (through array)
        //
        $lineRead = $fileArray[$i];


        //Make array of all "elements" in this line
        //
        $lineArray = explode("$separator",$lineRead);


        //Get manufacturers articlenumber
        //
        if (isset($lineArray[$articleNrFieldNr])) {

                $articleNumberManufacturer = $lineArray[$articleNrFieldNr];

        }

        else {

                $articleNumberManufacturer = 0;

        }


        //Get saldo for this product
        //
        if (isset($lineArray[$articleNrFieldNr])) {

                $saldo = $lineArray[$saldoFieldNr];

        }

        else {

                $saldo = 0;

        }

        //There is no data on this row
        //set saldo and articlenr to zero, so nothing happens
        //
        if (strlen($lineRead)==0) {

                $saldo = 0;
                $articleNumberManufacturer = 0;

        }


        //echo "<br>ARTICLENR: $articleNumberManufacturer<br>";
        //echo "SALDO: $saldo<br>";



        //Articlenr exists in line
        //
        if (intval($articleNumberManufacturer)>0) {


        //Get ID of product (if there is any in varupiratens db)
        //skip the product if the saldo is the same as in
        //the textfile
        //
        $sql = "SELECT IDVara FROM tbvara WHERE Varunamn =
'$prefix$articleNumberManufacturer' LIMIT 1;";
        $querys = mysql_query($sql);
        $dbArray = mysql_fetch_array($querys);
        $IDVara = $dbArray["IDVara"];
        if ($IDVara == Null) {$IDVara = 0;}


        //If product is found, then update saldo
        //
        if (intval($IDVara)>0) {

                $sql = "UPDATE tbvara SET Saldo=$saldo WHERE IDVara=$IDVara 
LIMIT 1;";
                $querys = mysql_query($sql);
                echo "QUERY DB -> $sql<br>";

        }

        //END Articlenr exists in line
        }

}
mysql_close();
}

?>

/G
@varupiraten.se

--
Internal Virus Database is out-of-date.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 2005-01-19

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to