PHP's simplest example tutorial for generating XML documents

Source: Internet
Author: User

<?php

MySQL tutorial _connect (' localhost ', ' root ', ' 1****** ') or Die (' database server no exists! ');
mysql_select_db (' wk ') or Die (' Database error! ');
mysql_query ("SET NAMES ' GBK '");//set document CharSet encode


function Createxml () {
$tag = 0;
$head = ' <?xml version= ' 1.0 ' encoding= ' gb2312 '?> <channel> ';
$sql = "SELECT * from Wk_works ORDER by id DESC";
$res =mysql_query ($sql) or Die (Mysql_error ());
while ($rs =mysql_fetch_array ($res)) {
if ($tag ==0) {
$STP = "<item class=" ". $rs [' W_type ']." "uid=". $rs [' m_id ']. "" Name= ". $this->get_name ($rs [' m_id '])." "Portrait = "". $rs [' W_head ']. "" Blogname = "". $rs [' Blogname ']. "" Url= "user.php?id=". $rs [' m_id ']. "poll =". $rs [' W_support ']. "" ></item> ";
}else{
$STP. = "<item class=" ". $rs [' W_type ']." "uid=". $rs [' m_id ']. "Name=". $this->get_name ($rs [' m_id ']). "" Portrait= "". $rs [' W_head ']. "" Blogname = "". $rs [' Blogname ']. "" Url= "user.php?id=". $rs [' m_id ']. "poll =". $rs [' W_ Support ']. "></item>";
}
$tag + +;
}
$foot = ' </channel> ';
$cont =fopen ("Xml/111cn.net.xml", ' W ');
Fwrite ($cont, $head. $stp. $foot);
Fclose ($cont);
}

function Get_name ($id) {
$sqle = "Select Id,m_uid from Wk_member where id= ' $id '";
$relt = mysql_query ($sqle);
$reus = Mysql_fetch_array ($relt);
return $reus [' M_uid '];
}
?>

Original reprint of this site annotated: www.111cn.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.