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

解决方案 »

  1.   

    没看明白...你是想从数据库里读出url 然后替换掉你的xml文件里的loc?
    本来想怎么样?
    结果上面的代码怎么样?
      

  2.   

    啥意思?
    把@tihuan@换成$dd,然后$dd里面又有个@tihuan@?
    而且所有的操作包括连接数据库读文件写文件全部放循环里?
      

  3.   

    交给helloyou0了 老人家要去睡觉了,日 给那个垃圾黑客代码弄得眼都花了.
      

  4.   

    就是loc增加地址啊。
    运行的话 1次循环OK啊。
    运行2次循环就看不懂了
      

  5.   

    好吧,牛牛交待的任务不敢不完成.....大概改写成这样,你再试试吧,有错上来说一声<?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);
    $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>
      

  6.   

    本帖最后由 xuzuning 于 2011-12-29 09:25:12 编辑
      

  7.   

    看了老大的提示,查了下资料,补充一下受影响的函数包括 stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype() 和 fileperms()。 
      

  8.   

    Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in
      

  9.   

    稍微修正一下照着改吧
    $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
    }
      

  10.   


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