Harch84 has asked for the wisdom of the Perl Monks concerning the following question:
The same logic is applied to the destination point with a similar query:$originsql = qq{ SELECT a.stop_reference, b.service_id, distance(Point +FromText('POINT($origin)', 27700),east_north), c.route_number FROM bu +s_stops a, service b, routes c WHERE distance(PointFromText('POINT($o +rigin)', 27700),east_north) < 200 AND a.stop_reference = b.stop_refer +ence AND b.service_id = c.service_id ORDER BY b.service_id, distance( +PointFromText('POINT($origin)', 27700),east_north)}; $sth = $dbh->prepare( $originsql ); $sth->execute(); $sth->bind_columns( undef, \$origin_stops, \$origin_service, \$origin_ +distance, \$origin_route_number); while ($sth->fetch()) { if ($orig_service != $last_service_id) { print "The bus stop located nearest to your Origin area is: " +.$origin_stops."<br />\n"; print "And the bus stop is ".$origin_distance." metres away from y +our location <br />\n"; print "This stop serves route number ".$origin_route_number." <p>< +p/>\n"; $last_orig_service_id = $origin_service; } }
Now what I need to be able to do is the compare the "$origin_service" to the "$destination_service". Now a simple if($origin_service == $destination_service) clause wont work as it seems to only compare the last two routes from each query whereas I need it to loop through all of the results for each and find matching pairs. One idea I had was to enter each origin and destination service numbers into two arrays and then compare them both? Or would I need some sort of double foreach statement to loop through both the origin and destination numbers finding mathcing pairs? I have tried many optins but cant seem to figure it out! Your help will be much appreciated. Thanks$destsql = qq{ SELECT a.stop_reference, b.service_id, distance(PointFr +omText('POINT($dest)', 27700),east_north), c.route_number FROM bus_st +ops a, service b, routes c WHERE distance(PointFromText('POINT($dest) +', 27700),east_north) < 200 AND a.stop_reference = b.stop_reference A +ND b.service_id = c.service_id ORDER BY b.service_id, distance(PointF +romText('POINT($dest)', 27700),east_north)}; $sth = $dbh->prepare( $destsql ); $sth->execute(); $sth->bind_columns( undef, \$destination_stops, \$destination_service, + \$destination_distance, \$destination_route_number); while ($sth->fetch()) { if ($dest_service != $last_service_id) { print "The bus stop located nearest to your Origin area is: " +.$destination_stops."<br />\n"; print "And the bus stop is ".$destination_distance." metres away f +rom your location <br />\n"; print "This stop serves route number ".$destination_route_number." + <p><p/>\n"; $last_dest_service_id = $destination_service; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing two variables from different loops
by almut (Canon) on Jul 05, 2007 at 01:30 UTC | |
|
Re: Comparing two variables from different loops
by GrandFather (Saint) on Jul 05, 2007 at 01:32 UTC | |
|
Re: Comparing two variables from different loops
by Anonymous Monk on Jul 05, 2007 at 01:59 UTC | |
by Eimi Metamorphoumai (Deacon) on Jul 05, 2007 at 14:44 UTC | |
by atemon (Chaplain) on Jul 06, 2007 at 10:22 UTC | |
|
Re: Comparing two variables from different loops
by Harch84 (Acolyte) on Jul 05, 2007 at 09:13 UTC | |
by almut (Canon) on Jul 05, 2007 at 09:43 UTC |