Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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
Mysql SQL连接问题_Mysql_Sql_Join - Fatal编程技术网

Mysql SQL连接问题

Mysql SQL连接问题,mysql,sql,join,Mysql,Sql,Join,我想知道是否有人能帮助我 我在尝试合并来自两个mySQL数据库表的信息时遇到了一个问题 到目前为止,我提出的查询如下所示 <?php require("phpfile.php"); // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("markers"); $parnode = $dom->appendChild($node

我想知道是否有人能帮助我

我在尝试合并来自两个mySQL数据库表的信息时遇到了一个问题

到目前为止,我提出的查询如下所示

<?php 
require("phpfile.php"); 

// Start XML file, create parent node 

$dom = new DOMDocument("1.0"); 
$node = $dom->createElement("markers"); 
$parnode = $dom->appendChild($node); 

// Opens a connection to a MySQL server 

$connection=mysql_connect ("hostname", $username, $password); 
if (!$connection) { die('Not connected : ' . mysql_error());} 

// Set the active MySQL database 

$db_selected = mysql_select_db($database, $connection); 
if (!$db_selected) { 
die ('Can\'t use db : ' . mysql_error()); 
} 

$query = "SELECT findid,
                 findosgb36lat,
                 findosgb36lon,
                 findcategory,
                 findname,
                 finddescription
          FROM   finds
          WHERE  makepublic = 'Yes'
            AND  sites.sitetype,
                 sites.sitedescription,
                 sites.siteosgb36lat,
                 sites.osgb36lon";  
$result = mysql_query($query); 
if (!$result) { 
die('Invalid query: ' . mysql_error()); 
} 

header("Content-type: text/xml"); 

// Iterate through the rows, adding XML nodes for each 

while ($row = @mysql_fetch_assoc($result)){ 
// ADD TO XML DOCUMENT NODE 
$node = $dom->createElement("marker"); 
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("findosgb36lat",$row['findosgb36lat']); 
$newnode->setAttribute("findosgb36lon",$row['findosgb36lon']); 
$newnode->setAttribute("findcategory",$row['findcategory']); 
$newnode->setAttribute("findname",$row['findname']);
$newnode->setAttribute("finddescription",$row['finddescription']);
} 

echo $dom->saveXML(); 

?>

对表格结构做出一些大的假设:

      SELECT s.site_id,
             s.sitetype,
             s.sitedescription,
             s.siteosgb36lat,
             s.osgb36lon,
             f.findid,
             f.findosgb36lat,
             f.findosgb36lon,
             f.findcategory,
             f.findname,
             f.finddescription
      FROM   sites s
      LEFT OUTER JOIN finds f on s.site_id = f.site_id and f.makepublic = 'Yes'

非常感谢你在这方面的帮助。我今天一直在研究这个问题,通过使用“UNIONALL”查询解决了所有问题。亲切问候

如果表之间没有公共字段,您希望它们以何种方式相互关联?您可能在寻找联合吗?听起来更像是一个联合,而不是一个联接,但是如果没有一个公共列,您如何预测数据的对齐?(除非我没有正确理解表的结合)每个表的模式是什么?如果它们是相同的,或者选择了等效的字段,则可以使用union.p.s。根据性能的不同,只有在需要时才建立DOM才有意义,而不是在建立数据库之前。(如果/当无法建立SQL连接时,创建DOM是没有用的)嗨,非常感谢回复我的帖子。“联盟”可能是一条路,我不太确定。这样做的原因是,我在“sites”表中有lat和lng字段,在“finds”表中有另一组字段,我想尝试合并成一个节点行,然后将其加载到HTML页面中。友善的regards@IHRM:说真的,正如Jim H所说,如果我们要提出合理的查询方法,我们真的需要查看您正在使用的表的结构。您好,我现在已经在我原来的帖子中添加了表结构。友善的regards@IHRM:在哪里?我看不到它们,也没有显示你修改了原来的帖子。