2017-08-02 69 views
0
<?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 >= 45000) 
    { 
     $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'); 

    } 
} 
?> 

文件中的数据卡在变量$的数据,只需要使用它的数据插入信息的XML网站地图PHP的MySQL拆分45000

如何通过创建网站地图的代码继续45000点的记录每个站点地图(sitemap1.xml,sitemap2.xml)

谁能帮助?

+0

'45.000'到PHP是一个小数,使用'45000'。查看分页查询。你也最好使用'> ='你的'=='可能永远不会发生。 – chris85

+0

已更改代码。谢谢! – sysrq

回答

0

在你的SQL语句中使用偏移和限制。

$part = (int) $_GET['part']; // Use http://domain/url?part=0 for first part and so on 
if ($part < 0) { 
    $part = 0; // To prevent illegal query 
} 

$perPart = 45000; 
$offset = $part * $perPart; 

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

注:mysql_ -functions已被弃用,并编写新的代码时,不应再使用。请参阅php.net/mysql_query上的红色警告。考虑迁移到MySQLi或PDO。