Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql连接表数据,需要在1个查询中从两者中拖出数据_Php_Mysql_Xml - Fatal编程技术网

Php Mysql连接表数据,需要在1个查询中从两者中拖出数据

Php Mysql连接表数据,需要在1个查询中从两者中拖出数据,php,mysql,xml,Php,Mysql,Xml,因此,我正在基于mysql表中的数据生成一个XML文件,但需要能够使用我的查询从2个表中获取所需的数据,并且不确定如何执行此操作。详情如下: TABLE: store_locations =================================== store_location_id country latitude longitude =================================== TABLE: store_locations_descriptions ==

因此,我正在基于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();
//根据数据库中的存储数据生成XML文件的函数
函数fn\u store\u locator\u generate\u xml(){
$qur=db_get_字段(“此处需要加入查询”);
$ans=mysql\U查询($qur);
$output.=”
";
while($row=mysql\u fetch\u数组($ans))
{
$output.=''.$row['name'].'';
$output.=''.$row['description'].'';
$output.=“”;
$output.=''.$row['name'].'';
$output.=''.$row['description'].'';
$output.=''.$row['description'].'';
$output.=“”;
$output.=''.$行['latitude'],“$行['latitude']。”;
$output.=“”;
$output.=“”;
$output.=“”;
} 
$output.=“”;
$file_name=“gallers.xml”;
$file\u pointer=fopen($file\u name,“w+”);
fwrite($file_指针,“$output”);
fclose($file\u指针);
}
//生成XML文件
fn_存储_定位器_生成_xml();

非常感谢

选择*FROM store\u locations加入store\u locations\u描述,但您应该看看mysql加入教程,加入在操作数据库数据时是必不可少的,例如:

选择*FROM store\u locations加入store\u描述,但您应该看看mysql加入教程,连接在处理数据库中的数据时非常重要,例如:

试试这个

select s.foo sd.foo
from store_locations s
join store_locations_descriptions sd
on s.store_location_id = sd.store_location_id
试试这个

select s.foo sd.foo
from store_locations s
join store_locations_descriptions sd
on s.store_location_id = sd.store_location_id

看起来你只需要加入。我假设这些表之间有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
您当然应该了解联接是如何工作的:

看起来您只需要加入。我假设这些表之间有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
您当然应该了解联接是如何工作的:

了解。了解。我似乎收到了警告:mysql\u fetch\u array():在第128行的/home/oneline/public\u html/artisan/dev/addons/store\u locator/func.php中,提供的参数不是有效的mysql结果资源,输出是:您有权尝试直接对DB执行查询吗?通过phpmyadmin的mysql客户端或其他什么?我运行查询并按预期返回结果,不确定为什么它没有传递到xml文件-可能是mysql_fetch_数组问题我做了一些假设,您是否连接到数据库并使用
mysql_select_DB
选择了一个模式?另外,我不知道你的
db_get_字段
做什么-
$qur
应该就是上面的sql。我现在正在研究它,感谢你提供了选择数据的解决方案:)我似乎收到了警告:mysql_fetch_array():在第128行的/home/oneline/public_html/artisan/dev/addons/store_locator/func.php中,提供的参数不是有效的MySQL结果资源,输出是:您有权尝试直接对DB执行查询吗?通过phpmyadmin的mysql客户端或其他什么?我运行查询并按预期返回结果,不确定为什么它没有传递到xml文件-可能是mysql_fetch_数组问题我做了一些假设,您是否连接到数据库并使用
mysql_select_DB
选择了一个模式?另外,我也不知道你的
db\u get\u字段
做了什么-
$qur
应该就是上面的sql。我现在正在研究它,感谢你提供了选择数据的解决方案:)