Has anyone see an error like "Undefined Offset" before. Every where I look I see that it referrs to an undefined var which doesnt seem right.

Undefined Offset on line 20

Code is as follows:

<?php
include('sql_connect.php');
$truncsql = "TRUNCATE TABLE allproperty";
mysql_query($truncsql) or die(mysql_error());
function parselistings($thefile, $thetable)
{
    // $truncsql="TRUNCATE TABLE ".$thetable."";
    // mysql_query($truncsql) or die(mysql_error());
    $file_contents = file("$thefile");
    // $file_contents = file('sampletest.txt');
    for ($i = 3; $i < sizeof($file_contents)-1; $i++) {
        $line = ($file_contents[$i + 1]); //Plus One to get rid of the table header information
        $line = addslashes($line); //Delimit Special chars that will mess up the insert.
        $line = trim($line);
        $arr = explode("\t", $line); 
        // print_r($arr);
        $junk = array_shift($arr);
        $junk = array_pop($arr);
//line 19 - 21 Begins Here
       for ($j = 0;$j < 107;$j++) {
            $newarr[$j] = $arr[$j];
        } 

        $sql = 'INSERT INTO ' . $thetable . ' VALUES (" ","' . implode('","', $newarr) . '")';
        mysql_query($sql);
        if (mysql_error()) {
            echo mysql_error() . "<br>\n";
        } 
        echo "<pre>";
        echo $sql;
        echo "</pre>"; 
        // }
        // else{
        // if ($i % 80 ==0) echo "<br>";
        // echo".";
    } 
} 
parselistings("/usr/local/orc-0.7.12/orcdata/test/Property_A.txt", 'allproperty');
parselistings("/usr/local/orc-0.7.12/orcdata/test/Property_B.txt", 'allproperty');
parselistings("/usr/local/orc-0.7.12/orcdata/test/Property_C.txt", 'allproperty');
// parselistings("/usr/local/orc-0.7.12/orcdata/test/Property_D.txt",'allproperty');
parselistings("/usr/local/orc-0.7.12/orcdata/test/Property_E.txt", 'allproperty');

?>

Any ideas would be appreciated.

Jared

In this line

for ($j = 0;$j < 107;$j++) {

you are assuming there are 107 lines when there aren't. You'd be better to use

for ($j = 0;$j < count($arr);$j++) {
This article has been dead for over six months. Start a new discussion instead.