Sitemap Mysql PHP divided into result quantities

2
<?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 'conexao.php';
include 'acoes.php';

$sql = mysql_query("select nome, nota from aluno");

while ($string = mysql_fetch_array($sql)){?>
            <url>
                <loc>http://www.escola.com.br/<?echo     removerosAcentos($string['nome']);?>/<?echo $string['nota'];?></loc>
                <changefreq>weekly</changefreq>
            </url>
<?php } ?> 
</urlset>

This code generates a sitemap (pulling from the database)

I need to generate a sitemap with 45 thousand (sitemap1.xml) and after reaching 45 thousand results another sitemap (sitemap2.xml) and so on.

There is a column named "numero" (Ex: 054322123) that can be used to sort. I have no idea how to do this. Can anyone help me in detail? Thanks!

    
asked by anonymous 01.08.2017 / 17:38

1 answer

1

If you run a counter no longer solves it?

<?php

include 'conexao.php';
include 'acoes.php';

$sql = mysql_query("select nome, nota from aluno");

$a = 0;
while ($string = mysql_fetch_array($sql))
{
    if ($a == 0)
    {
        $data = '<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">';
        $data .= '<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
        $data .= '<urlset>';
    }

    $data .= '<url>';
    $data .= '<loc>http://www.escola.com.br/' . removerosAcentos($string['nome']);
    $data .= $string['nota'] . '</loc>';
    $data .= '<changefreq>weekly</changefreq>';
    $data .= '</url>';
    $a += 1;
    if ($a == 45.000)
    {
        $data .= '</urlset>';
        $a = 0;

        $nome_arquivo = uniqid();
        header('Content-disposition: attachment; filename="' . $nome_arquivo . '.xml"');
        header('Content-type: "text/xml"; charset="utf8"');
        readfile($nome_arquivo . '.xml');
 // Os dados do arquivo estão presos na variável $data, basta usar os dados dela pra inserir as informações na XML
//Aqui você faz a saída individual pra cada arquivo de 45.000 registros
    }
}
?> 

The way you are now, every 45.00 lines will be generated a new id to name a new file, but you will need to study how to generate this individual xml with PHP, you can use several classes, I believe XMLWritter is the easiest .

    
01.08.2017 / 19:24