<?xml version="1.0" encoding="utf-8"?>
<products>
<category categoryName="Electronics">
<product productName="Camera Lenses Collection" productID="DSCF0001" thumbPath="thumbs/Electronics/camera_lenses_collection-other.jpg" productPrice="250.50">
<sizes>
<size>10</size>
<size>20</size>
<size>30</size>
<size>40</size>
<size>50</size>
</sizes>
<colors>
<color>Red</color>
<color>Blue</color>
<color>Green</color>
<color>Yellow</color>
<color>Pink</color>
</colors>
</category>
</product>
</products>
-hi我需要通过循环从表中加载数据。请帮我 - 如何从数据库生成xml文件?
答案 0 :(得分:0)
从数据库生成xml文件很简单。你不需要循环就行了。
模型功能
function getDataForXML(){
return $query = $this->db->get('my_table');
//Here you should note i am returning
//the query object instead of
//$query->result() or $query->result_array()
}
控制器
function get_report()
{
$this->load->model('my_model');
$this->load->dbutil();
$this->load->helper('file');
// get the object
$report = $this->my_model->getDataForXML();
//pass it to db utility function
$new_report = $this->dbutil->xml_from_result($report);
//Now use it to write file. write_file helper function will do it
write_file('xml_file.xml',$new_report);
//Done
}
现在可以使用名为xml_file.xml的新文件了!
资源
并且