PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Wed May 23, 2018 5:20 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Jun 25, 2012 10:14 pm 
Forum Newbie
User avatar

Joined: Sat Feb 04, 2012 7:29 pm
Posts: 6
Location: Deer Park, TX USA

I am in need of some guidance in solving a couple of issues and want to apologize beforehand for the lengthy summary. Issue one; I am trying to save a filtered mySQL select to a DOMDocument in a folder on the server and it does not seem to be saving the file. The folder attributes is set to 777 so there is not a permissions issue and I have confirmed that a file can be saved to it. Issue two; I need to call a javascript function using a Post Method (i.e., submit button) and I am unsure on how to do that.

URL to a demo page:

This is what I have to populate dataTable and create checkbox in the first column

Syntax: [ Download ] [ Hide ]
<form name="formWellLocators" onsubmit="javascript&#058;load();" method="post">    
      <table align="center" cellpadding="0" cellspacing="0" border="1" id="dataTable" width="100%">
            <th><input name="checkAll" type="checkbox" value="1" onclick="javascript&#058;checkThemAll(this);" /></th>
            <th><input type="text" name="<?=$row['api']?>" value="Filter API" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['state']?>" value="Filter State" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['county']?>" value="Filter County" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['operator']?>" value="Filter Operator" class="search_init" /></th>
                        <th><input type="text" name="<?=$row['spud_date']?>" value="Filter SPUD Date" class="search_init" /></th>
            <th><input type="text" name="<?=$row['lease_well_no']?>" value="Filter Lease/Well No" class="search_init" /></th>
            <th><img src="picts/Check_UnCheck.png" /></th> <!--Check All / Uncheck All Checkbox-->
            <th>SPUD Date</th>
            <th>Lease / Well No</th>
          <!--Start Loop-->
        while ($row = mysql_fetch_array($result)) {
            <td align="center"><input type="checkbox" name="CheckedWell[]" value="<?=$row['id']?>"></td> <!--Individual Check Boxes for the Check All / Uncheck All Button-->
            <td width="120"><?=$row['api']?></td>
            <td align="center"><?=$row['state']?></td>
            <td align="center" width="100"><?=$row['spud_date']?></td>
          <!--End Loop-->

Once the desired checkbox(s) has been selected and the "Refresh Map" button clicked

Syntax: [ Download ] [ Hide ]
<input type="submit" name="CheckedWells" value="Refresh Map" align="left" />

the following code is triggered to create a new DOMDocument and save it as a XML file:

Syntax: [ Download ] [ Hide ]
        if(isset($_POST['CheckedWell'])) {
           foreach($_POST['CheckedWell'] as $item) {
                  $query = ("SELECT * FROM rig_locator WHERE id=$item");
                  $CheckedResult = mysql_query($query);
                  mysql_query($query) or trigger_error("SQL: $sql, ERROR: " . mysql_error(), E_USER_ERROR);
                  // Start XML file, create parent node
                  $dom = new DOMDocument("1.0");
                  $dom->formatOutput = true;
                  $node = $dom->createElement("markers");
                  $parnode = $dom->appendChild($node);   
                  header("Content-type: text/xml");

                  // Iterate through the rows, adding XML nodes for each         
                  while ($row = mysql_fetch_assoc($CheckedResult)){
                        // Add to XML Document Node
                        $node = $dom->createElement("marker");
                        $newnode = $parnode->appendChild($node);
                        $newnode->setAttribute("ID", $row['id']);
                        $newnode->setAttribute("API", $row['api']);
                        $newnode->setAttribute("State", $row['state']);
                        $newnode->setAttribute("County", $row['county']);
                        $newnode->setAttribute("LeaseWellNo", $row['lease_well_no']);
                        $newnode->setAttribute("FieldZone", $row['field_zone']);
                        $newnode->setAttribute("WellBoreType", $row['well_bore_type']);
                        $newnode->setAttribute("Depth", $row['depth']);
                        $newnode->setAttribute("RigNameNo", $row['rig_name_no']);
                        $newnode->setAttribute("SPUD", $row['spud_date']);
                        $newnode->setAttribute("CurrentActivity", $row['current_activity']);
                        $newnode->setAttribute("LAT", $row['lat']);
                        $newnode->setAttribute("LON", $row['lon']);
                  // Save DomDocument as CheckedWells.xml
                  //echo $dom->saveXML() . "\n";                 

and the javascript load() function should be triggered by the on submit event

Syntax: [ Download ] [ Hide ]
<form name="formWellLocators" onsubmit="javascript&#058;load();" method="post">  

Finally the javascript function populates the map with the map markers of the selected wells. Below is the load() function:

Syntax: [ Download ] [ Hide ]
function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(36.77046585083,-98.30557250977), 4);

        GDownloadUrl("xml/CheckedWells.xml", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
                        var state = markers[i].getAttribute("State");
                        var county = markers[i].getAttribute("County");  
            var operator = markers[i].getAttribute("Operator");
            var field_zone = markers[i].getAttribute("FieldZone");
                        var lease_well_no = markers[i].getAttribute("LeaseWellNo");
                        var api = markers[i].getAttribute("API");
            var well_bore_type = markers[i].getAttribute("WellBoreType");
                        var spud_date = markers[i].getAttribute("SPUD");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("LAT")),
                        var directions = "" + encodeURIComponent(point);
            var marker = createMarker(point, state, county, operator, field_zone, lease_well_no, api, well_bore_type, spud_date, directions);

Can someone assist with solving the DOMDocument not saving problem and guide me on the proper way to call a javascript function via a onsubmit event. I am open to any ideas or suggestions. Thanks in advance for your help and guidance.



Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot] and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group