Retrieving field name of Database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux