我正在尝试创建 sitemap.xml 文件并从我的数据库中获取所有品牌。我有以下代码:
<?php
header("Content-type: text/xml");
echo'<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
echo'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
include 'includes/modules/connections/db.php'; //database connection
$brands = mysql_query("SELECT * FROM brands WHERE brand_status = 1"); //Select all brands
$row_brands = mysql_fetch_assoc($brands);
do { ?>
<url>
<?php
//Check when brand pages was last time updated
$brand_update = mysql_query("SELECT * FROM user_history WHERE brand_id = ".$row_brands['brand_id']." ORDER BY uh_date DESC");
$row_brand_update = mysql_fetch_assoc($brand_update)
?>
<loc>http://www.example.com/brand/<? echo $row_brands['brand_url']; ?>/</loc>
<lastmod><?php echo $row_brand_update['uh_date']; ?></lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
<?php } while ($row_brands = mysql_fetch_assoc($brands)); ?>
</urlset>
但是我得到以下错误。我尝试了很多更改,但总是会出现不同的错误。有人在上面的代码中看到导致以下错误的问题吗?
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<br/>
<b>Warning</b>
: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
<b>
/hermes/bosoraweb060/b2763/ipg.example/sitemap-brands.php
</b>
on line
<b>8</b>
<br/>
<url>
<br/>
<b>Warning</b>
: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
<b>
/hermes/bosoraweb060/b2763/ipg.example/sitemap-brands.php
</b>
on line
<b>15</b>
<br/>
<loc>http://www.example.com/brand//</loc>
<lastmod/>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
<br/>
<b>Warning</b>
: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
<b>
/hermes/bosoraweb060/b2763/ipg.example/sitemap-brands.php
</b>
on line
<b>22</b>
<br/>
</urlset>
非常感谢得到帮助!