Splitting mysql results
Posted: Wed Jun 17, 2009 1:48 pm
Hello,
New to the forum, first post.
I've been dabbling in PHP for a bit now and I'm catching on but I just got myself into an issue I can't resolve. I'm using the code below to create a sitemap from my database. The problem I'm facing is figuring out how to make this a linkable sitemap tree. Most SE's only accept sitemaps of 50,000 or less urls. My site generates millions (over 80) webpages so I need to split these up into separate files but make them linkable from one to the next per googles specs. Basically I need this script to count every 50,000 urls and then create a new page of 50,000 urls and so on and so forth.
Can anyone help?
Thanks in advance!
Joshua
New to the forum, first post.
I've been dabbling in PHP for a bit now and I'm catching on but I just got myself into an issue I can't resolve. I'm using the code below to create a sitemap from my database. The problem I'm facing is figuring out how to make this a linkable sitemap tree. Most SE's only accept sitemaps of 50,000 or less urls. My site generates millions (over 80) webpages so I need to split these up into separate files but make them linkable from one to the next per googles specs. Basically I need this script to count every 50,000 urls and then create a new page of 50,000 urls and so on and so forth.
Code: Select all
<?php
$conn = mysql_connect("localhost", "", "") or die('Error connecting to mysql');
mysql_select_db("");
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
echo "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$sql = "select * from table GROUP BY name";
$rs = mysql_query($sql, $conn);
while($row=mysql_fetch_array($rs)) {
echo "<url>";
$row['mod_firm'] = str_replace(" ","_",$row['firm']);
$row['mod_firm'] = str_replace("/","-",$row['mod_firm']);
echo "<loc><a href=\"http://mydomain/".$row['mod_firm']."-".$row['id'].".html\">http://www.mydomain.com/".$row['mod_firm']."-".$row['id'].".html</a></loc>\n";
echo "<lastmod>2008-09-29</lastmod>\n";
echo "<changefreq>monthly</changefreq>\n";
echo "
<priority>0.5</priority>\n";
echo "</url><br>";
}
echo "</urlset>" ;
mysql_close($conn);
?>
Thanks in advance!
Joshua