I have asked this question earlier, but could not get a reply that
worked :-(

I have a single login_success.php file where I have written a function

IsWithinFixedGeofence(point) 
{
...... 
.... 
... 
if ( distance <= MINIMUMDISTANCE ) 
 { 
 return PointsOfInterest[i]; 
 } 

I want to be able to store the following three properties of
PointsOfInterest. I am not sure if I need the command "return" as
well. All I want to do is store:

1) index i
2) .lat
3) .lng

into 3 PHP variables.

something like -

IsWithinFixedGeofence(point) 
 { 
   ... 
   .. 
  if ( distance <= MINIMUMDISTANCE ) 
  { 
   <? $lat ?> = PointsOfInterest[i].lat; 
   <? $lng ?> = PointsOfInterest[i].lng; 
   <? $index ?> = i; 
} 

and then be able to use $lat, $lng to center the map to that point.

 // Display the map, with some controls and set the initial location 
    var map = new GMap2(document.getElementById("map")); 
    map.addControl(new GSmallMapControl()); 
    map.setCenter(new GLatLng(<? $lat ?>, <? $lng ?>),15); 

and use the index in a dynamic SQL query like this -

$result = mysql_query("SELECT cities.cityname, cities.citybuslink, 
markers.information, markers.name, markers.address , markers.picture 
FROM cities, markers where markerid = <? $index ?> AND markers.cityid = 
cities.cityid "); 

Do I really need to store the JS function return value into PHP variables or can I use the function IsWithinFixedGeofence()'s return value as a source everywhere else too ?

Something like

IsWithinFixedGeofence().lat

IswithinFixedGeofence().lng

and

IsWithinFixedGeofence().index

I heard AJAX would also work with something like this, but I am not
sure how to use it in this context..

I would be extremely grateful if you could help me with this
problem.

Best regards,
Amol

Since JavaScript runs in the browser after PHP os processed on the server the only way to get this information to the server is to submit the data as either POST or GET data or use Ajax. But you can't affect the PHP used to render the page as it is long done processing the page by the time the JavaScript comes into play.

Hi there,

Thanks very much for the reply.

I just figured out that instead of passing the javascript variables into PHP, I should store these into JS variables only.


if I use this code

IsWithinGeofence(point)
{
....
...

if(distance <= minimiumdistance)

{
document.write(PointsOfInterest[i].lat);
}

}

It displays the correct value of lat from the database. in case here 56.4856.


I declared 3 global variables on the top of the document in order to assign them the values of latitude, longitude and index of the PointsOfInterest


i.e.

var latitude =12 ; //12 is assigned just to test if this variable is being correctly assigned or not

var longitude;

var index ;

IsWithinGeofence(point)
{
....
...

if(distance <= minimiumdistance)

{
[B]latitude =  PointsOfInterest[i].lat;
longitude = PointsOfInterest[i].lng;
index = i;[/B]

}

}

document.write(latitude);

The above command is displaying the value 12 instead of getting the value 56.4856 from PointsOfInterest.lat

Why is this so ??

Best regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.