hobbiton73 Posted October 7, 2011 Share Posted October 7, 2011 I wonder whether someone may be able to help me please. I'm currently running the code below (originating from nearby.org.uk) to convert OS Grid References to Latitude and Longtiude co-ordinates. function converttolatlng() { var gr = document.getElementById('osgridref').value; var osgb = new GT_OSGB(); if (osgb.parseGridRef(gr)) { var wgs84 = osgb.getWGS84(); document.getElementById('osgb36lat').value = wgs84.latitude; document.getElementById('osgb36lon').value = wgs84.longitude; } else { document.getElementById('osgb36lat').value = "n/a"; document.getElementById('osgb36lon').value = "n/a"; } } This code is run through a 'click' event from a button on a HTML form and then the record is saved to a mySQL database. However, once a month, I have a list of approx 20,000 OS Grid References which need converting and saving to the same mySQL database. To do this manually on a button click wouldn't be very practical, so I've been working on doing this automatically. I may very well be doing this the wrong way, but I've been using the PHP script below to extract the two pieces of information I need from the xml file, the first is the 'Name, and the second is the 'NGR', and it is this field that needs converting. <? $objDOM = new DOMDocument(); $objDOM->load("scheduledmonuments.xml"); $Details = $objDOM->getElementsByTagName("Details"); foreach( $Details as $value ) { $Name = $value->getElementsByTagName("Name"); $name = $Name->item(0)->nodeValue; $NGR = $value->getElementsByTagName("NGR"); $ngr = $NGR->item(0)->nodeValue; echo "$name :: $ngr <br>"; } ?> This is where I've become a little stuck because I'm not sure how to get the data converted and to a point where it can be saved to the relevant fields in my database. I just wondered whether someone would perhaps take a look at this please and let me know what I need to do. Many thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 7, 2011 Share Posted October 7, 2011 You can't "run" JavaScript via PHP. PHP is run on the server and JavaScript is run on the client. I would think you should be looking for a PHP solution to generate the results. But, if you cannot find one, then one option would be to use PHP to generate a page with ALL the records you need to process, then create a JavaScript function to process each record on the page. But, instead of trying to update each record in the database as it is processed, you could instead have the results stored in form fields on the page. Then once all the records are processed, submit the page one time and have a PHP page to update all the records simultaneously. Quote Link to comment 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.