PHPcode & lt ;? PHP $ content & lt ;? Xmlversion & quot; 1.0 & quot; encoding & quot; UTF-8 & quot ;? & Gt; & lt; urlsetxmlns & quot; case study of www. sitemaps. orgschemassitemap0.9 & quo php generating sitemap
PHP code
'; // The following code specifies the data, but the actual requirement is to use SQL to complete $ data_array = array ('loc' => 'http: // www.sslook.com/', 'priority' => '1. 0', 'lastmod' => '2017-06-03T04: 20: 32-08:00 ', 'changefreq' => 'alway'), array ('loc' => 'http: // www.sslook.com/', 'priority' => '0. 5 ', 'lastmod' => '2017-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) {// currently, this function will cause Data confusion after processing $ item ="
\ N "; $ item. ="
". $ Data ['loc ']."
\ N "; $ item. ="
". $ Data ['priority ']."
\ N "; $ item. ="
". $ Data ['lastmod']."
\ N "; $ item. ="
". $ Data ['changefreq']."
\ N "; $ item. ="
\ N "; return $ item ;}
In the code, what should I do if I use an SQL statement to assign values to arrays? This is the case below, but all the xml files output by the test are hhh... or something.
PHP code
$ Query = SQL statement; $ result = mysql_query ($ query); while ($ row = mysql_fetch_array ($ result) {$ data_array ['loc '] = "limit"; $ data_array ['priority '] = '1. 0'; $ data_array ['lastmod'] = '2017-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'] = '2017-12-12 ';
$ Data_array ['changefreq'] = 'weekly ';
}
When this while loop is repeated, the array value data_array is overwritten, so a value is added.
What does hhh mean by changing it to the following? is there something in the database? let's take 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'] = '2017-12-12 '; // you are bound to death. $ data_array [$ I] ['changefreq'] = 'weekly '; ++ $ I ;}