<?phpfor($i=$_GET['kaishi'];$i<=$_GET['jiesu'];$i++)
{
mysql_connect("localhost","aaa","abcdef"); //本端数据库
mysql_select_db("url");
mysql_query("set names 'utf-8'");
$sql="SELECT * FROM `text` where id=$i";
$sqll=mysql_query($sql);
$sqll=mysql_fetch_array($sqll);
$sql=$sqll['url'];
$dd="
<url>
<loc>$sql</loc>
<lastmod>2011-12-20</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
@tihuan@
";
$fp=fopen("sitemap.txt","r");
$str=fread($fp,filesize("sitemap.txt"));
$str=str_replace("@tihuan@",$dd,$str);
$handle=fopen("sitemap.txt","w");
fwrite($handle,$str);
fclose($handle);}?>
<form action="" method="get">
数据库开始的地方 <input type="text" name="kaishi"/>
数据库开始结束地方 <input type="text" name="jiesu"/>
<input type="submit">
</form>
<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
<loc>http://sina.com</loc>
<lastmod>2011-12-02</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
@tihuan@
</urlset>
{
mysql_connect("localhost","aaa","abcdef"); //本端数据库
mysql_select_db("url");
mysql_query("set names 'utf-8'");
$sql="SELECT * FROM `text` where id=$i";
$sqll=mysql_query($sql);
$sqll=mysql_fetch_array($sqll);
$sql=$sqll['url'];
$dd="
<url>
<loc>$sql</loc>
<lastmod>2011-12-20</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
@tihuan@
";
$fp=fopen("sitemap.txt","r");
$str=fread($fp,filesize("sitemap.txt"));
$str=str_replace("@tihuan@",$dd,$str);
$handle=fopen("sitemap.txt","w");
fwrite($handle,$str);
fclose($handle);}?>
<form action="" method="get">
数据库开始的地方 <input type="text" name="kaishi"/>
数据库开始结束地方 <input type="text" name="jiesu"/>
<input type="submit">
</form>
<?xml version="1.0" encoding="UTF-8" ?>
<urlset>
<url>
<loc>http://sina.com</loc>
<lastmod>2011-12-02</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
@tihuan@
</urlset>
本来想怎么样?
结果上面的代码怎么样?
把@tihuan@换成$dd,然后$dd里面又有个@tihuan@?
而且所有的操作包括连接数据库读文件写文件全部放循环里?
运行的话 1次循环OK啊。
运行2次循环就看不懂了
mysql_connect("localhost","aaa","abcdef");
mysql_select_db("url");
mysql_query("set names 'utf-8'");$begin=intval($_GET['kaishi']);
$end=intval($_GET['jiesu']);
$sql="SELECT * FROM `text` where id between {$begin} and {$end} ";
$sqll=mysql_query($sql);
$sqll=mysql_fetch_array($sqll);$dd='';
while($result=mysql_fetch_array($sqll))
{
$loc=$result['url'];
if(!empty($loc)){
$dd.="
<url>
<loc>{$sql}</loc>
<lastmod>2011-12-20</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
";
}
}$str=file_get_contents("sitemap.txt");
$str=str_replace("@tihuan@",$dd."\n@tihuan@\n",$str);
file_put_contents("sitemap.txt", $str);?>
<form action="" method="get">
ss <input type="text" name="kaishi"/>
ee <input type="text" name="jiesu"/>
<input type="submit">
</form>
$begin=$_GET['kaishi']+0;
$end=$_GET['jiesu']+0;$from=min($begin,$end);
$to=max($begin,$end);
$sql="SELECT * FROM `text` where id between {$from} and {$to} ";
$sqll=mysql_query($sql) or die(mysql_error());
//$sqll=mysql_fetch_array($sqll);$dd='';
while($result=mysql_fetch_array($sqll))
{
//some code here
}
<?php
mysql_connect("localhost","aaa","abcdef");
mysql_select_db("url");
mysql_query("set names 'utf-8'");$begin=intval($_GET['kaishi']);
$end=intval($_GET['jiesu']);
$sql="SELECT * FROM `text` where id between {$begin} and {$end} ";
$sqll=mysql_query($sql);
$dd='';
while($result=mysql_fetch_array($sqll))
{
$loc=$result['url'];
if(!empty($loc)){
$dd.="
<url>
<loc>{$loc}</loc>
<lastmod>2011-12-20</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
";
}
}$str=file_get_contents("sitemap.txt");
$str=str_replace("@tihuan@",$dd."\n@tihuan@\n",$str);
file_put_contents("sitemap.txt", $str);?>
<form action="" method="get">
ss <input type="text" name="kaishi"/>
ee <input type="text" name="jiesu"/>
<input type="submit">
</form>