在很多应用中我们都会用到xml,特别是互动设计的朋友哦flash+xml等,下面我们就来一个实时的php输出xml文件并进行分页吧.
php 输出xml文件实例代码如下:
- <?php
- require_once("Inc/Conn.php");
- $sql = "select * from ose";
- $result = mysql_query($sql) ;
- $total = mysql_num_rows($result);
- if( $total )
- {
- $pagesize =4;
- $pagecount=($total % $pagesize)?(int)($total / $pagesize)+1:$total/$pagesize;
- $page =isset($_GET['page'])?$_GET['page']:1;
- $start =($page>=1 && $page<=$pagecount)?$start=$pagesize*($page-1):$start=1;
- $sql.=" order by id desc limit $start,$pagesize" ;
- $result = mysql_query( $sql );
- while( $rs = mysql_fetch_array($result) )
- {
- $temp .= "<member id="".$rs['id']."" roomname="".$rs['User_Name'].""/>n";
- }
- }
- else
- {
- die('{result:"false"}');
- }
-
- echo "<?xml version="1.0" encoding="gb2312" ?>n<root>n<page now="$page" count="$pagecount"/>n<roomlist>n",$temp,"</roomlist>n</root>";
-
- ?>
|