Example of PHP generating site map

Source: Internet
Author: User
Examples of PHP generated sitemaps
PHP Code
  
  
  
   
    ';//The code below specifies the data, but the actual requirement is to use SQL to complete the $data_array=array (' loc ' = ' http://www.sslook.com/', ' Prio        Rity ' + ' 1.0 ', ' lastmod ' = ' 2012-06-03t04:20:32-08:00 ', ' changefreq ' = ' always ', array (        ' loc ' = ' http://www.sslook.com/', ' priority ' = ' 0.5 ', ' lastmod ' = ' 2012-06-03t04:20:32-08:00 ', ' Changefreq ' = ' daily '); foreach ($data _array as $data) {$content. =create_item ($data);} $content. = '
   
  '; $fp =fopen (' sitemap.xml ', ' w+ '); fwrite ($fp, $content); fclose ($fp); function Create_item ($data) {// The current test is that after the function is processed, the data is confused $item = "
  
   
    \ n ";
 $item. = " 
    
     ". $data [' Loc ']. "    
    \ n ";
 $item. = " 
    
     ". $data [' priority ']. "    
    \ n ";
 $item. = " 
    
     ". $data [' Lastmod ']. "    
    \ n ";
 $item. = " 
    
     ". $data [' Changefreq ']. "    
    \ n "; $item. = "
   
  \ n "; return $item;}

Where in the code the array is assigned, what do you do with the SQL statement? I am the bottom of this, but the test output XML file is all HHH ... What
PHP Code
  
   $query = SQL statement; $result = mysql_query ($query), while ($row = Mysql_fetch_array ($result)) {    $data _array[' loc ']= "http ://zufang.sslook.com/sh/$ran/$row [0];    $data _array[' priority ']= ' 1.0 ';    $data _array[' lastmod ']= ' 2012-12-12 ';    $data _array[' changefreq ']= ' Weekly ';    }



------Solution--------------------
while ($row = Mysql_fetch_array ($result))
{$data _array[' loc ']= "http://zufang.sslook.com/sh/$ran/$row [0];
$data _array[' priority ']= ' 1.0 ';
$data _array[' lastmod ']= ' 2012-12-12 ';
$data _array[' changefreq ']= ' weekly ';
}
This while looping again, the array value Data_array is overwritten again, so the end is a value, add flag
Change to the following, are HHH What do you mean, database stuff, send a look
PHP Code
$i = 0;while ($row = mysql_fetch_array ($result)) {    $data _array[$i] [' Loc ']= ' http://zufang.sslook.com/sh/$ran/$row [0] ";    $data _array[$i] [' Priority ']= ' 1.0 ';    $data _array[$i] [' lastmod ']= ' 2012-12-12 ';//These are dead to you    $data _array[$i [' Changefreq ']= ' weekly ';    + + $i;    }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.