用PHP生成多个SQL表以生成站点地图 [英] multiple SQL tables with PHP to generate sitemap

查看:95
本文介绍了用PHP生成多个SQL表以生成站点地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用PHP生成的站点地图,实际上它仅调用表零售商,如下所示:

I have a sitemap that's generated with PHP and actually its calling only the table retailers as below:

$query = "select * from retailers WHERE status='active' ORDER BY added DESC";

并构造为:

while ($row = mysql_fetch_array($result))
{  
    $i_url = SITE_URL.'loja/'.$row['slug_title'];
    $year = substr($row['added'],0,4);
    $month  = substr($row['added'],5,2);
    $day  = substr($row['added'],8,2);
    $i_date = ''.$year.'-'.$month.'-'.$day.'';

    // you can assign whatever changefreq and priority you like
    // changefreg - optional
    // priority - optional
    echo  
    '
    <url>
    <loc>'.$i_url.'</loc>
    <lastmod>'.$i_date.'</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
    </url>
    ';
}

问题是,只有零售商能分页显示它的到来,我需要再获得3个表,但我无法想到一种在其中调用和构造更多东西的方法,也许是PHP条件?

The problem is, only retailers page its coming, i need to get some more 3 tables, but i can't think on a way to call and construct more things inside that, maybe a PHP condition?

感谢大家的宝贵时间!

推荐答案

我建议您创建一个函数来处理所需的查询或子查询

I suggest you to create a function to handle the queries or subqueries you need

像 主要代码

while ($row = mysql_fetch_array($result))
{  
    $i_url = SITE_URL.'loja/'.$row['slug_title'];
    $year = substr($row['added'],0,4);
    $month  = substr($row['added'],5,2);
    $day  = substr($row['added'],8,2);
    $i_date = ''.$year.'-'.$month.'-'.$day.'';

    $data = subquery('what i need here', 'another param');

    echo  
    '
    <url>
    <loc>'.$i_url.'</loc>
    <lastmod>'.$i_date.'</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
    </url>
    ';
}

function subquery($firstparam, $secondparam)
{
  $myquery = "SELECT * FROM ".$firstparam;
  //more code

  $result = 'my query result';

  return $result;
}

这样,您可以基于主查询调用子查询,可以创建更多的功能或仅创建具有不同类型的功能,从而可以在一个函数中执行不同的查询.

With this you can call a subquery based on the main query, you can create more funcionts or create only one with different types that, can able you to do different queries in one function.

这篇关于用PHP生成多个SQL表以生成站点地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆