1

因此,我正在根据 mysql 表中的数据生成一个 XML 文件,但需要能够使用我的查询从 2 个表中获取我想要的数据,并且不确定如何执行此操作。详情如下:

TABLE: store_locations
===================================
store_location_id
country
latitude
longitude
===================================

TABLE: store_locations_descriptions
===================================
store_location_id
name
description
city
===================================

PHP函数:

// Function to generate XML file based on store data from database
function fn_store_locator_generate_xml(){
    $qur = db_get_field("JOIN QUERY WANTED HERE");
    $ans=mysql_query($qur);
    $output.= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://earth.google.com/kml/2.2\">
<Document>";
    while($row=mysql_fetch_array($ans))
    {
      $output.="<name>".$row['name']."</name>";
      $output.="<description>".$row['description']."</surname>";
      $output.="<Placemark>";
      $output.="<name>".$row['name']."</name>";
      $output.="<Snippet>".$row['description']."</Snippet>";
      $output.="<description>".$row['description']."</description>";
      $output.="<Point>";
      $output.="<coordinates>".$row['latitude'].",".$row['longitude']."</coordinates>";
      $output.="</Point>";
      $output.="</Placemark>";
      $output.="</person>";
    } 
    $output.="</Document>";

    $file_name = "galleries.xml";
    $file_pointer = fopen($file_name, "w+");
    fwrite($file_pointer, "$output");
    fclose($file_pointer);
}
// generate the XML file
fn_store_locator_generate_xml();

提前谢谢了!

4

4 回答 4

1

看起来你只需要一个加入。我假设您在这些表之间有 1 对 1 的关系。

select s.store_location_id,
    s.country,
    s.latitude,
    s.longitude,
    d.name,
    d.description,
    d.city
from store_locations s
    join store_locations_descriptions d
    on s.store_location_id = d.store_location_id

你当然应该看看连接是如何工作的:http: //www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php

于 2012-05-18T09:00:22.637 回答
0

SELECT * FROM store_locations JOIN store_locations_descriptions,但你应该看看 mysql join tutorial,join 在操作数据库中的数据时必不可少,例如:mysql join tutorial

于 2012-05-18T08:59:15.630 回答
0
SELECT sl.country, sl.latitude, sl.longitude, sld.name, sld.description, sld.city
FROM store_locations sl
JOIN store_location_descriptions sld
ON sl.store_location_id=sld.store_location_id
于 2012-05-18T08:59:47.427 回答
0

尝试这个

select s.foo sd.foo
from store_locations s
join store_locations_descriptions sd
on s.store_location_id = sd.store_location_id
于 2012-05-18T09:00:19.953 回答