Jump to content

PHP writing XML


awebbdesign

Recommended Posts

I have started to play with Ajax and have had some results, however to do a dual combo box for IE I had to write some XML as IE hates innerHTML. Anyhow The code below works except for the fact that in the for loop its printed literally, for some reason I can't use double qoutes, can anyone help!

 

<?php

 

header("Content-Type: text/xml");

 

require('adminarea/inc-connect.php');

 

//$id = $_GET['q'];

$id = 3914;

 

$from = mysql_query("SELECT tdata.*, tdata.fieldb AS theplace, tjoins.*

FROM tdata

LEFT JOIN tjoins

ON tdata.id = tjoins.tdata_fk

WHERE tjoins.tdata_id = '$id' ORDER BY tdata.fieldb");

 

$num = mysql_num_rows($from);

 

print '<?xml version="1.0" encoding="ISO-8859-1" ?>

<selectChoice><selectElement><formName>myform</formName><formElem>s2</formElem></selectElement>';

 

if(mysql_num_rows($from) != 0) {

 

print "<entry><optionText>Select...$id, $num</optionText><optionValue>NS</optionValue></entry>";

 

for ($i = 0; $i < mysql_num_rows($from); $i++) {

 

$row = mysql_fetch_object($from);

print '<entry><optionText>$row->theplace</optionText><optionValue>$row->theid</optionValue></entry>';

 

}

 

} else {

 

print "<entry><optionText>No Options ($id, $iid)</optionText><optionValue>NA</optionValue></entry>";

 

}

 

print "</selectChoice>";

 

?>

Link to comment
Share on other sites

Hmmm, 1st thing I tried, I am suspecting now it could be the parser, is there anything wrong with the following???

 

      function FillDropDown(){

        var xmlDoc = this.req.responseXML.documentElement;     

       

        //alert(xmlDoc);

 

        var xSel = xmlDoc.                                           

          getElementsByTagName('selectElement')[0];                 

        var strFName = xSel.                                         

          childNodes[0].firstChild.nodeValue;                       

        var strEName = xSel.                                         

          childNodes[1].firstChild.nodeValue;                       

           

        var objDDL = document.forms[strFName].                       

          elements[strEName];                                       

        objDDL.options.length = 0;                                   

           

        var xRows = xmlDoc.                                           

          getElementsByTagName('entry');                             

        for(i=0;i<xRows.length;i++){                                 

          var theText = xRows.                                     

              childNodes[0].firstChild.nodeValue;                     

          var theValue = xRows.                                   

              childNodes[1].firstChild.nodeValue;                     

          var option = new Option(theText,                           

                            theValue);                         

          objDDL.options.add(option,                                 

                          objDDL.options.length);                     

        }                                                             

      } 

 

The website Im getting this to work on is: http://www.v-cars.com/bka3.php

 

Any help will be most grateful.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.