首页 > 编程开发 > Php > 正文  
查询数据生成XML并显示的例子(基于PHP+MySQL)
出自:红都网 2002年08月13日 21:51
//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

a

a

</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>

】【http://www.trainlinux.com】【Close
『相关资料』
正则表达式例子:获得某个网页上的所有超裢接 (2002-08-13 21:50)
正则表达式例子:将MM/DD/YYYY格式的日期转换为YYYY-MM-DD格式 (2002-08-13 21:50)
正则表达式例子:在一个字符串中查找另一个字符串 (2002-08-13 21:50)
Apache如日中天,微软奋起直追 (2002-08-13 21:49)
Home 

诚恩Linux培训工作室