Jump to content

Recommended Posts

i have a script that I did not write that is used for importing TIGER/Line data into a MySQL database. when i run the script it gives me a parse error. I cannot find the error for the life of me. See if you can find it.

 

The parse error is:

Parse error: parse error, expecting `')'' in /Library/WebServer/Documents/bar/secure/mrp/geocode/tigerload.php on line 80

 

here is the suspect code snipit around line 80

 

function processData($data, $rt2=null) {
    global $dbConn;

    // ====== Builds a linedata string similiar to:
    //  -121952185 45642435,-121952674 45642755,-121953000 45642755,-121953072 45642719
    //
    // It uses the fr/to lat/long of the type1 record ( = $data) for the start and end points
    // and if this TLID has a corresponding type2 record ($rt1 != null) then the intermediate
    // points in that type2 record are included.  Once built, the string is added to the $data
    // array and stored in the database.
    //
    $linedata = $data["frlong"] . " " . substr($data["frlat"],1) . ",";
    if ( $rt2 != null ) {
        foreach($rt2 as $rtsq => $ll) {
            for($x=1; $x<11; $x++) {
                if ( $ll["Lng$x"] == "+000000000" ) break;
                $linedata .= $ll["Lng$x"] . " " . substr($ll["Lat$x"],'1') . ",";
            }
        }
    }
    $linedata .= $data["tolong"] . " " . substr($data["tolat"],1);
    $data["linedata"] = $linedata;
   
    // ==== Store all of the type1 record info and the new linedata to the completechain table
    // using the handy AutoExecute method in the ADODB library. 
    return $dbConn->AutoExecute("completechain", $data, 1);
   
}

 

 

Any Ideas?

Link to comment
https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/
Share on other sites

line 80 is exactly the code i just posted a second ago

 

77 $linedata = $data["frlong"] . " " . substr($data["frlat"],1) . ",";

78    if ( $rt2 != null ) {

79        foreach($rt2 as $rtsq => $ll) {

80            for($x=1; $x<11; $x++) {

81              if ( $ll["Lng$x"] == "+000000000" ) break;

82                $linedata .= $ll["Lng$x"] . " " . substr($ll["Lat$x"],'1') . ",";

83            }

84        }

85    }

 

now i am getting wrong parameter counts for fgets:

 

Wrong parameter count for fgets() in /Library/WebServer/Documents/bar/secure/mrp/geocode/tigerload.php on line 27

 

Here is the whole script:

 


<?
require_once('adodb/adodb.inc.php');

set_time_limit(300);

$dbConn = ADONewConnection("mysql://USER:PASSWORD@localhost/DATABASE"); 
if (!$dbConn) { echo("Connection failed");  exit; }

complete_chain("41", "051");    // Process Multnomah County, Oregon

// ================================================================================= complete_chain
// Main function for processing a single county file
//
function complete_chain($state, $county) {

    $rt1path = "data/$state/$county/TGR${state}${county}.RT1";
    $rt2path = "data/$state/$county/TGR${state}${county}.RT2";

    $tFile_RT1 = @fopen($rt1path, "r");
    $tFile_RT2 = @fopen($rt2path, "r");

    if ( !$tFile_RT1 || !$tFile_RT2 ) {
        echo "Couldn't open a file: <br>";
        echo "RT1: $rt1path RT2: $rt2path<br />";
        return;
    }
   
    echo "Starting...<br />";

    // ===  Load all RT2 records into an array with TLID as the Key
    echo "Loading Type2 Records...<br />";
    $rt2def = datadict("RT2");
    while ( ($line = fgets($tFile_RT2)) ) {
        $data = parseData($line, $rt2def);

        $rt2[$data["TLID"]][$data["RTSQ"]] = $data;
        $i++;
    }

    // ===  Read and process RT1 records, storing the combined data to the database
    $ttl=0; $cnt=0;
    $rt1def = datadict("RT1");
    echo "Processing Type1 Records...<br />";
    while ( ($line = fgets($tFile_RT1)) ) {
        $data = parseData($line, $rt1def);
       
        if ( $cnt++ % 1000 == 0 ) {
            echo " - $cnt records processed<br />"; flush();
        }
       
        // ===  To limit the number of records added to the database, and to speed up the import
        // you can add a conditional here.  This is quite useful when testing so you don't have
        // to load the entire county file.
        //if ( $data["zipl"] != "97232" || $data["zipr"] != "97232") continue;
       
        // === Process the Type1 record, also passing in any associated Type2 records if they exsist
        if ( array_key_exists($data["tlid"], $rt2) ) {
            $ttl += processData($data, $rt2[$data["tlid"]]);
        } else {
            $ttl += processData($data);
        }
       
        if ( $ttl % 500 == 0 ) {
            echo " -- $ttl records added<br />"; flush();
        }
    }
   
    echo "Finished.  Added $ttl completechain records<br />";
}

// ================================================================================= processData
// Returns field names and lengths for various TIGER/Line files
//
function processData($data, $rt2=null) {
    global $dbConn;

    // ====== Builds a linedata string similiar to:
    //  -121952185 45642435,-121952674 45642755,-121953000 45642755,-121953072 45642719
    //
    // It uses the fr/to lat/long of the type1 record ( = $data) for the start and end points
    // and if this TLID has a corresponding type2 record ($rt1 != null) then the intermediate
    // points in that type2 record are included.  Once built, the string is added to the $data
    // array and stored in the database.
    //
    $linedata = $data["frlong"] . " " . substr($data["frlat"],1) . ",";
    if ( $rt2 != null ) {
        foreach($rt2 as $rtsq => $ll) {
            for($x=1; $x<11; $x++) {
                if ( $ll["Lng$x"] == "+000000000" ) break;
                $linedata .= $ll["Lng$x"] . " " . substr($ll["Lat$x"],'1') . ",";
            }
        }
    }
    $linedata .= $data["tolong"] . " " . substr($data["tolat"],1);
    $data["linedata"] = $linedata;
   
    // ==== Store all of the type1 record info and the new linedata to the completechain table
    // using the handy AutoExecute method in the ADODB library. 
    return $dbConn->AutoExecute("completechain", $data, 1);
   
}

// ================================================================================= datadict
// Returns field names and lengths for various TIGER/Line files
//
function datadict($rt) {

    switch ($rt) {
        case "RT1":
            $dd = array("rt" => 1, "version" => 4, "tlid" => 10, "side1" => 1, "source" => 1,
                "fedirp" => 2, "fename" => 30, "fetype" => 4, "fedirs" => 2,"cfcc" => 3,
                "fraddl" => 11, "toaddl" => 11, "fraddr" => 11, "toaddr" => 11,
                "friaddl" => 1, "toiaddl" => 1, "friaddr" => 1, "toiaddr" => 1,
                "zipl" => 5, "zipr" => 5, "aianhhfpl" => 5, "aianhhfpr" => 5,
                "aihhtlil" => 1, "aihhtlir" => 1, "census1" => 1, "census2" => 1,
                "statel" => 2, "stater" => 2, "countyl" => 3, "countyr" => 3,
                "cousubl" => 5, "cousubr" => 5, "submcdl" => 5, "submcdr" => 5,
                "placel" => 5, "placer" => 5, "tractl" => 6, "tractr" => 6,
                "blockl" => 4, "blockr" => 4,
                "frlong" => 10, "frlat" => 9, "tolong" => 10,"tolat" => 9);  
            break;
        case "RT2":
            $dd = array("RT" => 1, "Version" => 4, "TLID" => 10, "RTSQ" => 3,
                "Lng1" => 10, "Lat1" => 9, "Lng2" => 10, "Lat2" => 9,
                "Lng3" => 10, "Lat3" => 9, "Lng4" => 10, "Lat4" => 9,
                "Lng5" => 10, "Lat5" => 9, "Lng6" => 10, "Lat6" => 9,
                "Lng7" => 10, "Lat7" => 9, "Lng8" => 10, "Lat8" => 9,
                "Lng9" => 10, "Lat9" => 9, "Lng10" => 10, "Lat10" => 9);
            break;
    }

    return $dd;
}

// ================================================================================= parseData
// Returns an array of data from a string ($line) based on the fields in $def
//
function parseData($line, $def) {
    $start = 0;
    foreach($def as $name=>$len) {
        $ret[$name] = trim(substr($line, $start, $len));
        $start += $len;
    }
    return $ret;
}

// ==== Helper/debug functions

function view($obj) {
    echo "<pre>";
    print_r($obj);
    echo "</pre>";
}

?>

I can say that either the parameter is invalid or something is missing.Please use the following syntactical notations:

<?php

 

$file = fopen("test.txt","r");//open file test.txt for reading purpose

echo fgets($file);//print out the first line of the file

fclose($file);//close the file

 

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.