PHP help for an ASP Developer

I'm an ASP .Net developer working on a PHP project.  I've worked on ASP 2.0 in the past and thought that some of that knowledge would apply here.

I am attempting to create a page using an xml data island (see code snipet).  The problem I am having is that the php code doesn't seem to execute. When I view the rendered html, in place of my xml data island, I see the php code (tags included) that should have executed to return the xml data.

I'd imagine this would be a fairly easy question to answer for anyone even remotely experienced in PHP development.

Thanks in advance,

Red.
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style type="text/css">
        #map {
            width: 800px;
            height: 450px;
            border: 1px solid black;
        }

    </style>
    <script type="text/javascript" src="test.php"></script>
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    <script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
    <script type="text/javascript">
        <!--
        // complex map object
        var map;
 
    // Start position for the map (hardcoded here for simplicity,
    // but maybe you want to get from URL params)
        var lat=53.402; //latitude
        var lon =-6.451; //longitude
        var zoom=17;
        //var doc=begining.XMLDocument;

        //var    elm=doc.documentElement;

//Then to access lower level elements...

        //var elm.childNodes[0].getElement();
        

        var SinglePoint = OpenLayers.Class.create();
        SinglePoint.prototype = OpenLayers.Class.inherit(OpenLayers.Handler.Point, {
            createFeature: function(evt) {
                this.control.layer.removeFeatures(this.control.layer.features);
                OpenLayers.Handler.Point.prototype.createFeature.apply(this, arguments);
            }
        });

        var start_style = OpenLayers.Util.applyDefaults({
            externalGraphic: "start.png",
            graphicWidth: 18,
            graphicHeight: 26,
            graphicYOffset: -26,
            graphicOpacity: 1
        }, OpenLayers.Feature.Vector.style['default']);

        var stop_style = OpenLayers.Util.applyDefaults({
            externalGraphic: "stop.png",
            graphicWidth: 18,
            graphicHeight: 26,
            graphicYOffset: -26,
            graphicOpacity: 1
        }, OpenLayers.Feature.Vector.style['default']);

         var result_style = OpenLayers.Util.applyDefaults({
             strokeWidth: 3,
             strokeColor: "#ff0000",
             fillOpacity: 0
         }, OpenLayers.Feature.Vector.style['default']);

        // global variables
        var map, parser, start, stop, downtown, result, controls;

        
        
        
            function Lon2Merc(lon) {

    return 20037508.34 * lon / 180;

}



function Lat2Merc(lat) {

    var PI = 3.14159265358979323846;

    lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / (PI / 180);

    return 20037508.34 * lat / 180;

}    
        

 
        function init(){
            map = new OpenLayers.Map('map',
                    { maxExtent: new OpenLayers.Bounds(-6.451,53.179,-6.036,53.402),
                      numZoomLevels: 19,
                      maxResolution: 156543.0399,
                      units: 'm',
                      projection: new OpenLayers.Projection("EPSG:900913"),
                      displayProjection: new OpenLayers.Projection("EPSG:4326")
                    });
 
            var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
 
            var layerTah = new OpenLayers.Layer.OSM.Osmarender("Tiles@Home");
 
            map.addLayers([layerMapnik,layerTah]);
 
            var pois = new OpenLayers.Layer.Text( "My Points",
                    { location:"./textfile.txt",
                      projection: map.displayProjection
                    });
            map.addLayer(pois);

            // Add Images layer
            var imgs = new OpenLayers.Layer.Text( "Images",
                { location: "http://aisling.cs.dit.ie/~emma.mullen/test.php",
                projection: new OpenLayers.Projection("EPSG:4326")
                });
            map.addLayer(imgs);

            

 
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MousePosition());

            start = new OpenLayers.Layer.Vector("Start point", {style: start_style});
            stop = new OpenLayers.Layer.Vector("End point", {style: stop_style});


                 map.addLayer(start);
                 map.addLayer(stop);
                // map.addLayer(result);    

 
            var lonLat = new OpenLayers.LonLat(lon, lat).transform(map.displayProjection,  map.projection);
            if (!map.getCenter()) map.setCenter (lonLat, zoom);

         controls = {
           start: new OpenLayers.Control.DrawFeature(start, SinglePoint),
              stop: new OpenLayers.Control.DrawFeature(stop, SinglePoint)
            }
            for (var key in controls) {
                map.addControl(controls[key]);
            }
        }

        function toggleControl(element) {
             
            for (key in controls) {
                if (element.value == key && element.checked) {
                
           
                    controls[key].activate();
                } else {
                    controls[key].deactivate();
                }
            }
        }

        

 

           
</script>
</head>

<?php
     
       // Database connection settings
       define("PG_DB"  , "test");
       define("PG_HOST", "localhost");
       define("PG_USER", "postgres");
       define("PG_PORT", "5432");
       define("TABLE",   "ways");
       
 
     
       $counter = $pathlength = 0;
     
       // Retrieve start point
      $start = split(' ',$_REQUEST['startpoint']);
     
       $startPoint = array($start[0], $start[1]);
      
      
      
      
      
       // Retrieve end point
       $end = split(' ',$_REQUEST['finalpoint']);
     
      $endPoint = array($end[0], $end[1]);
      
      
     
       // Find the nearest edge
       $startEdge = findNearestEdge($startPoint);
      
     
       $endEdge   = findNearestEdge($endPoint);
     
       // FUNCTION findNearestEdge
       function findNearestEdge($lonlat) {
         
         // Connect to database
         $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." password=".PG_PASS." user=".PG_USER);
         
         $sql = "SELECT gid, source, target, the_geom,
                  distance(the_geom, GeometryFromText(
                       'POINT(".$lonlat[0]." ".$lonlat[1].")', 900913)) AS dist
                 FROM ".TABLE." 
                 WHERE the_geom && setsrid(
                       'BOX3D(".($lonlat[0]-200)."
                              ".($lonlat[1]-200).",
                              ".($lonlat[0]+200)."
                              ".($lonlat[1]+200).")'::box3d, 900913)
                 ORDER BY dist LIMIT 1";
         
      
     
     
         $query = pg_query($con,$sql); 
         
         $edge['gid']      = pg_fetch_result($query, 0, 0); 
         $edge['source']   = pg_fetch_result($query, 0, 1); 
         $edge['target']   = pg_fetch_result($query, 0, 2); 
         $edge['the_geom'] = pg_fetch_result($query, 0, 3); 
     
         // Close database connection
         pg_close($con);
     
         return $edge;
       }
      ?>






<HTML>
 <body onload="init()">
    <div id="map"></div>                
        
      <xml id=begining>
        <xml id="edgedata">
            <root>
                <?php findNearestEdge() ?>
            </root>
        </xml>
        
        <xml id="id">

        </xml>

        <xml id="wkt">

        </xml>

        <xml id="length">

        </xml>
        </xml>
        <table>
        <tr><td>
            <INPUT TYPE=text VALUE="-6.44923,53.40078" Id="hidtxtLonLat" NAME="hidtxtLonLat" SIZE=100>
        </td></tr>
        </body>
        </HTML>

Open in new window

RedneckWonderlandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KendorCommented:
in your function findNearest Edge you are not outputing anything. thus line 247 won't show you anything.
 you might check the functions: echo and print.

you are also not giving any parameters to your function call. so $lonlat is unknown within the function...
0
KendorCommented:
what you might want to do is something like:
<?php
$a =  findNearestEdge($your_lonlat);

echo "<gid>".$a['gid']."</gid>";
echo "<source>".$a['source']."</source>";
echo "<target>".$a['target']."</target>";
echo "<the_geom>".$a['the_geom']."</the_geom>";

?>

or a little more sophisticated:

<?php
$a =  findNearestEdge($your_lonlat);

foreach ($a as $k => $v) {
    echo "<$k>$v</$k>";
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RedneckWonderlandAuthor Commented:
Sorry the code I posted wasn't correct.

I had actually changed the php function to accept no parameters and was taking the $edge value from the text box hidtxtLonLat.

I can't apologise enough for the mistake.  My head is truly wrecked at this stage.  Please see attached code snippet.
// FUNCTION findNearestEdge
       function findNearestEdge {

        $lonlat = hidtxtLonLat.text;

         
         // Connect to database
         $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." password=".PG_PASS." user=".PG_USER);
         
         $sql = "SELECT gid, source, target, the_geom,
                  distance(the_geom, GeometryFromText(
                       'POINT(".$lonlat[0]." ".$lonlat[1].")', 900913)) AS dist
                 FROM ".TABLE." 
                 WHERE the_geom && setsrid(
                       'BOX3D(".($lonlat[0]-200)."
                              ".($lonlat[1]-200).",
                              ".($lonlat[0]+200)."
                              ".($lonlat[1]+200).")'::box3d, 900913)
                 ORDER BY dist LIMIT 1";
         
      
     
     
         $query = pg_query($con,$sql); 
         
         $edge['gid']      = pg_fetch_result($query, 0, 0); 
         $edge['source']   = pg_fetch_result($query, 0, 1); 
         $edge['target']   = pg_fetch_result($query, 0, 2); 
         $edge['the_geom'] = pg_fetch_result($query, 0, 3); 
     
         // Close database connection
         pg_close($con);
     
         return $edge;
       }
      ?>
     


 <body onload="init()">
    <div id="map"></div>                
        
      <xml id=begining>
        <xml id="edgedata">
            <root>
                <?php findNearestEdge() ?>
            </root>
        </xml>
        
        <xml id="id">

        </xml>

        <xml id="wkt">

        </xml>

        <xml id="length">

        </xml>
        </xml>
        <table>
        <tr><td>
            <INPUT TYPE=text VALUE="-6.44923,53.40078" Id="hidtxtLonLat" NAME="hidtxtLonLat" SIZE=100>
        </td></tr>

        </table>
        </body>

Open in new window

0
KendorCommented:
ok - no problem. now, my first comments still apply. you are not outputing anything when calling findNearestEdge(). You have to work with the return value as I showed an example in comment 2.

in your posted function I find line 4 ($lonlat = hidtxtLonLat.text;) won't work. you are trying to get the fields value, right? but I believe it is not possible to access it like in javascript.

you might pass the value by post or get so that you can access it by $_REQUEST['whatever'] or $_GET['whatever'] or $_POST['whatever'].

the easiest would be if you'd point your browser to:
yourfile.php?hidtxt=your_requested_values_and_such_123_23

and then access it in your php like:
$theval = $_GET['hidtxt'];



0
RedneckWonderlandAuthor Commented:
Hi,

Sorry for the delayed response.  You're right of course.  There were other issues to do with the configuration of the web server.  That's the reason the php was not being processed as php.  But we would have had the issues you pointed out had we progressed past this issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.