a2bardeals Posted March 8, 2007 Share Posted March 8, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/ Share on other sites More sharing options...
itsmeArry Posted March 8, 2007 Share Posted March 8, 2007 try changing this $linedata .= $ll["Lng$x"] . " " . substr($ll["Lat$x"],'1') . ","; to $linedata .= $ll["Lng$x"] . " " . substr($ll["Lat$x"],1) . ","; Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202935 Share on other sites More sharing options...
a2bardeals Posted March 8, 2007 Author Share Posted March 8, 2007 did not fix the problem... i think it lies some where in the code: for($x=1; $x<11; $x++) what is the purpose of the semi-colons and could that be the reason? Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202949 Share on other sites More sharing options...
Jackanape Posted March 8, 2007 Share Posted March 8, 2007 What Exactly is line 79 and line 80? Usually the parenthesis hasn't been closed the line before... Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202952 Share on other sites More sharing options...
a2bardeals Posted March 8, 2007 Author Share Posted March 8, 2007 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 } Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202953 Share on other sites More sharing options...
linuxdream Posted March 8, 2007 Share Posted March 8, 2007 I may be completely off but... for($x=1; $x<11; $x++) { I didn't know you could have more than two ; in a for statement. Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202954 Share on other sites More sharing options...
a2bardeals Posted March 8, 2007 Author Share Posted March 8, 2007 i replaced the escape < with < and it seems to do the job Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202955 Share on other sites More sharing options...
Jackanape Posted March 8, 2007 Share Posted March 8, 2007 That's it: for($x=1; $x<11; $x++) { Is supposed to be: for($x=1; $x<11; $x++) { and somehow your code got html-ified... Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202956 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2007 Share Posted March 8, 2007 This line: <?php for($x=1; $x<11; $x++) ?> should be written <?php for($x=1; $x<11; $x++) ?> The corrected line is the way to write the start of a "for" loop. The semi-colons are part of the syntax. Ken Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202958 Share on other sites More sharing options...
a2bardeals Posted March 8, 2007 Author Share Posted March 8, 2007 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-202962 Share on other sites More sharing options...
rameshfaj Posted March 9, 2007 Share Posted March 9, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/41844-can-you-find-the-parse-error/#findComment-203284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.