if (count($input1) = 1) {
<?php$prefix1 = $_POST['prefix1'];$name1 = $_POST['name1'];$type1 = $_POST['type1'];$suffix1 = $_POST['suffix1'];$prefix2 = $_POST['prefix2'];$name2 = $_POST['name2'];$type2 = $_POST['type2'];$suffix2 = $_POST['suffix2'];$success = 1;$output = 1;street_process($prefix1,$name1,$type1,$suffix1,1,$success,$output);if ($success == 0) { not_found(1);} else { $output1=$ouput; }$success = 1;$output = 1;street_process($prefix2,$name2,$type2,$suffix2,2,$success,$output);if ($success == 0) { not_found(2);} else { $output2=$ouput; }build_form3($output1,$output2);// End main function// function street_processfunction street_process($prefix,$name,$type,$suffix,$iteration,&$success,&$output){ $name = strtoupper($name); $conn_string = "host=localhost port=5432 dbname=testKCstreets user=postgres password=*******"; $db = pg_connect($conn_string); $query="SELECT fullname FROM streets.roadtest WHERE st_name='$name'"; if ($prefix != "0") { $query .= " AND dirprefix='$prefix'"; } if ($suffix != "0") { $query .= " AND dirsuffix='$suffix'"; } if ($type != "0") { $query .= " AND st_type='$type'"; } $result = pg_query($db, $query); if (!$result) { echo "An error occured.\n"; exit; } for ($i=0; $i<pg_numrows($result); $i++){ $result_list[$i] = pg_fetch_result($result, $i, "fullname"); } if (is_null($result_list[0])) { return $success = 0; } else { $output = array_unique($result_list); sort($output); return; }}//function not_foundfunction not_found($iteration){ echo "Street number $iteration was not found.<br>"; echo "Please make sure the street you are searching for is in King County.<br>"; echo "Also, please check your spelling.<br>"; echo "Click the button below to return to the previous page.<br>"; echo "<form name=\"form2\" action=\"street_intersect.htm\"><input type=\"button\" value=\"Return\"></form>"; exit;}// function build_form3function build_form3($input1,$input2){ echo "<form name=\"form3\" action=\"intersect.php\" method=\"post\">"; if (count($input1) = 1) { echo "Street number 1 is:<br>"; echo $input1[0]; } else { echo "Multiple results were found for street number 1. Please select one:<br>" for ($i=0; $i<count($input1); $i++){ echo "<input type=\"radio\" name=\"street1", $i, "\" value=\"", $input1[$i], "\">"; echo $input1[$i]; echo "<br>"; } } echo "<br><br>"; if (count($input2) = 1) { echo "Street number 2 is:<br>"; echo $input2[0]; } else { echo "Multiple results were found for street number 2. Please select one:<br>" for ($i=0; $i<count($input2); $i++){ echo "<input type=\"radio\" name=\"street2", $i, "\" value=\"", $input2[$i], "\">"; echo $input2[$i]; echo "<br>"; } } echo "<br><br>"; echo "If these values are correct, click <i>Submit</i>.<br>"; echo "Otherwise, click <i>Return</i> to try again.<br>"; echo "<input type=\"submit\" name=\"submit\" value=\"submit\">"; echo "<input type=\"button\" name=\"return\" value=\"Return\" a href=\"street_intersect.htm\">"; echo "</form>"; exit;}?>
<?php////////////////////////// begin main function//////////////////////////// post variable declarations from street_intersect.htm$prefix1 = $_POST['prefix1']; // directional prefix$name1 = $_POST['name1'];$type1 = $_POST['type1'];$suffix1 = $_POST['suffix1']; // directional suffix$prefix2 = $_POST['prefix2'];$name2 = $_POST['name2'];$type2 = $_POST['type2'];$suffix2 = $_POST['suffix2'];$output1 = street_process($prefix1,$name1,$type1,$suffix1); // try to match the first streetif ($output1 == 0) { // no match of street name found not_found(1);}$output2 = street_process($prefix2,$name2,$type2,$suffix2); // try to match the second streetif ($output2 == 0) { not_found(2);}build_form3($output1,1); // build the formbuild_form3($output2,2);finalize_form();///////////////////////// End main function /////////////////////////////////////////////////////////////////////////// function street_process //// builds the query and performs the query //// returns zero if no match is found //// otherwise returns array of possible matches//////////////////////////////////////////////////function street_process($prefix,$name,$type,$suffix){ $name = strtoupper($name); $conn_string = "host=localhost port=5432 dbname=testKCstreets user=postgres password=******"; $db = pg_connect($conn_string); $query="SELECT fullname FROM streets.roadtest WHERE st_name='$name'"; if ($prefix != "0") { $query .= " AND dirprefix='$prefix'"; } if ($suffix != "0") { $query .= " AND dirsuffix='$suffix'"; } if ($type != "0") { $query .= " AND st_type='$type'"; } $result = pg_query($db, $query); if (!$result) { // could not connect to database echo "An error occured.\n"; exit; } for ($i=0; $i < pg_numrows($result); $i++){ $result_list[$i] = pg_fetch_result($result, $i, "fullname"); //only get fullname, not interested in spatial geometry at this time } if (is_null($result_list[0])) { // no match of street name found return 0; } else { $output = array_unique($result_list); // get rid of multiple instances sort($output); // reindex array after unique return $output; }}////////////////////////////////////////////////////////////////////////// function not_found //// called if street_process returns no matches //// terminates script and allows user to return to street_intersect.htm//////////////////////////////////////////////////////////////////////////function not_found($iteration){ echo "Street number $iteration was not found.<br>"; echo "Please make sure the street you are searching for is in King County.<br>"; echo "Also, please check your spelling.<br>"; echo "Click the button below to return to the previous page.<br>"; echo "<form name=\"form2\" action=\"\"><input type=\"button\" value=\"Return\" onClick=\"window.location='street_intersect.htm'\"></form>"; exit;}///////////////////////////////////////////////////////////////////////////////////////////////////////////// function build_form3 //// creates the query confirmation form //// if a street has multiple matches, user is instructed to choose which one s/he wants to use //// if a street has only one match, show it to the user //// if there are no matches, the script should have terminated already, but we'll check again just in case/////////////////////////////////////////////////////////////////////////////////////////////////////////////function build_form3($input,$iteration){ echo "<form name=\"form3\" action=\"intersect.php\" method=\"post\">"; if (count($input) < 1) { // if this happens, script should have already terminated, so this is here just to watch variables echo "An unknown error has occurred! Terminating."; exit; } elseif (count($input) == 1) { // query returned exactly 1 match echo "Street number $iteration is:<br>"; echo "<input type=\"hidden\" name=\"street", $iteration, "\" value=\"", $input[0], "\">"; // hidden text box echo $input[0]; } else { //implies count is greater than 1, multiple query matches echo "Multiple results were found for street number $iteration. Please select one:<br>"; for ($i=0; $i < count($input1); $i++){ echo "<input type=\"radio\" name=\"street", $iteration, "\" value=\"", $input[$i], "\">"; // radio buttons echo $input[$i]; echo "<br>"; } } echo "<br><br>";}/////////////////////////////////////////////////// function finalize_form //// writes submit and return buttons to the form//// doesn't accept or return arguments ///////////////////////////////////////////////////function finalize_form(){ echo "If these values are correct, click <i>Submit</i>.<br>"; echo "Otherwise, click <i>Return</i> to try again.<br>"; echo "<input type=\"submit\" name=\"submit\" value=\"submit\">"; echo "<input type=\"button\" name=\"return\" value=\"Return\" onClick=\"window.location='street_intersect.htm'\">"; echo "</form>"; exit;}?>