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; }