400-696-8028

查询数据生成XML并显示的例子(基于PHP+MySQL)

长沙北大青鸟作者:科泰校区匿名

摘要://TABLE create table tableurl( id int(5), sort int(2), click int(6), getday date, name char(30), link char(40), brief char(50), PRIMARY KEY (id) ) //XML FILE ------------------------------ <?php requi
//TABLE



create table tableurl(



id int(5),



sort int(2),



click int(6),



getday date,



name char(30),



link char(40),



brief char(50),



PRIMARY KEY (id)



)







//XML FILE



------------------------------



<?php



require("db.inc.php");







if(empty($order))



{$order='hot';



}



switch($order)



{



case 'hot':



$querystring="select * from tableurl order by click desc LIMIT 20";



break;



case 'new':



$querystring="select * from tableurl order by getday desc LIMIT 20";



}



$result=mysql_query($querystring,$db);



echo "<?xml version="1.0" encoding="gb2312"?>n";



echo "<?xml-stylesheet type="text/xsl" href="sitelist.xsl"?>";



echo "<URL>n";



while ($data=mysql_fetch_array($result))



{ echo "<WEBSITE ID="".$data["id"]."">n";



echo "<NAME>".$data["name"]."</NAME>n";



echo "<LINK>".$data["link"]."</LINK>n";



echo "<CLICK>".$data["click"]."</CLICK>n";



echo "<DATE>".$data["getday"]."</DATE>n";



echo "<BRIEF>".$data["brief"]."</BRIEF>n";



echo "</WEBSITE>n";



}



echo "</URL>n";



?>







//XSL FILE



------------------------------



<?xml version="1.0" encoding="gb2312" ?>



<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">



<xsl:template match="/">







<html>



<head>



<title>SITELIST.XML.PHP</title>



<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />



<style type="text/css">



body {font-size:9pt;line-height:16pt}



table {font-size:9pt;line-height:16pt}



a:link {color:#000000;text-decoration:underline}



a:visited {color:#000000;text-decoration:underline}



a:active {color:#000000;text-decoration:underline}



a.white:link {color:#ffffff;text-decoration:underline}



a.white:visited {color:#ffffff;text-decoration:underline}



a.white:active {color:#ffffff;text-decoration:underline}



</style>



</head>



<body>



<p align="center"><a href="sitelist.xml.php?order=hot">HOT</a>---<a href="sitelist.xml.php?order=new">NEW</a></p>







<table width="750" align="center" border="0" cellspacing="1" cellpadding="5" bgcolor="#cccccc">



<tr>



<td width="5%" bgcolor="#ffffff">ID</td>



<td width="30%" bgcolor="#ffffff">NAME</td>



<td width="20%" bgcolor="#ffffff">DATE</td>



<td width="5%" bgcolor="#ffffff">CLICK</td>



<td width="40%" bgcolor="#ffffff">BRIEF</td>



</tr>



<xsl:for-each select="URL/*">



<tr>



<td width="5%" bgcolor="#ffffff"><xsl:value-of select="@ID"/></td>



<td width="30%" bgcolor="#ffffff">



<a><xsl:attribute name="href">go.php?id=<xsl:value-of select="@ID"/></xsl:attribute>



<xsl:attribute name="target">_blank</xsl:attribute><xsl:value-of select="NAME"/></a>



</td>



<td width="20%" bgcolor="#ffffff"><xsl:value-of select="DATE"/></td>



<td width="5%" bgcolor="#ffffff"><xsl:value-of select="CLICK"/></td>



<td width="40%" bgcolor="#ffffff"><xsl:value-of select="BRIEF"/></td>



</tr>



</xsl:for-each>



</table>



<p align="center"> <a href="#" onclick="window.close()">CLOSE</a> </p>



</body>



</html>

关于我们
公司简介
发展历程
青鸟荣誉
联系我们
加入我们
青鸟课程
BCVE视频特效课程
BCUI全链路UI设计
BCSP软件开发专业
BCNT网络工程师
启能职业教育基础课程
长沙初中生学什么
长沙高中生学什么
长沙大学生学什么