Retrieving field name of Database

From: Date: Sun, 02 Feb 2003 12:16:10 +0000
Subject: Retrieving field name of Database
Groups: php.db php.general php.windows 
Request: Send a blank email to php-windows+get-18297@lists.php.net to get a copy of this message
Helloo people, I have to build a database abstraction class with support for XML output. My XML output has to look like this: <?xml version="1.0" ?> <result query="SELECT * FROM books"> <row number="1"> <field name="name">value</field> <field name="name">value</field> ... </row> <row number="2"> <field name="name">value</field> <field name="name">value</field> ... </row> .... .... </result> Well i almost got it, but how do i get all the field names of my MySQL tables? This is my code, a part of my database class. :
        /**
* getXMLDocument * * Get the result of your query back in XML document
   * @author        Davy Obdam
*/ function getXMLDocument() {
       //Create XML document
       if(!$this->xmlDoc = domxml_new_doc("1.0")) {
           die("[ERROR] Cant create XML document");
       }
       // Create root element
       $this->root_element = $this->xmlDoc->create_element("result");
       $this->root_element->set_attribute("query", $this->sqlQuery);
       //Get database fields and values
       $count = 0;
       while($this->fetchRow()) {
           $row_element = $this->xmlDoc->create_element("row");
           $n_row = $this->root_element->append_child($row_element);
           $row_number = $row_element->set_attribute("number" ,$count);
           $count++;
           // Get fieldnames and values
           for($i=0; $i<sizeof($this->sqlQuery); $i++) {
               $field_element = $this->xmlDoc->create_element("field");
               $n_field = $row_element->append_child($field_element);
               $field_name = $field_element->set_attribute("name", "name");
               $field_content = $field_element->append_child($this->xmlDoc->create_text_node(utf8_encode("text")));
           }
               
           $this->moveNext();
       }
       // Put everything together and show it
       $append_root = $this->xmlDoc->append_child($this->root_element);
       header("content-type:text/xml");
       echo $this->xmlDoc->dump_mem();
} Now all i get is one field <field name="name">whatever</field> in my XML output, but i should get 10 with this particular query.. Any help is appreciated, thanks for you time. Best regards, Davy Obdam mailto:info@davyobdam.com

« previous php.windows (#18297) next »