我有一个用PHP生成的站点地图,实际上它仅调用表零售商,如下所示:
$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条件?
感谢大家的宝贵时间!
我建议您创建一个函数来处理所需的查询或子查询
像主码
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; }
这样,您可以基于主查询调用子查询,可以创建更多的功能或仅创建具有不同类型的功能,从而可以在一个函数中执行不同的查询。