从PHP

时间:2017-07-05 08:04:13

标签: php mysql sql union

我看了一下,我真的很难看到如何克服这个问题。我看过UNION/UNION ALLJOIN,但我无法让它发挥作用。

基本上,我有来自三个MySQL表的数据。这三个表具有来自它的表单数据,并命名为 Fleet Facilities HAS 。数据具有相似的标题但信息不同。它们共享相同的4个标题:

ticket | agentname | dept | resolved

我有以下PHP代码在HTML表格中显示它但我无法从所有三个表格中显示它。 (我只能发布两张图片)

Facility Table

Fleet Table

$mysqli=mysqli_connect("example","root","toor","site");
include('config.php');    //include of db config file
include ('paginate.php'); //include of paginat page

$per_page = 25;         // number of results to show per page
$result = mysqli_query("SELECT * FROM fleet
                        UNION ALL
                        SELECT * FROM has
                        ORDER resolved BY ASC;");

我不是网络程序员。我从youtube和谷歌那里学到了什么。请在可能的情况下解释您的答案

1 个答案:

答案 0 :(得分:0)

您有语法错误:ORDER已解决ASC,应该是:ORDER BY已解决ASC

您是否尝试在选择中指定列?尝试这样的事情:

    SELECT ticket, agentname, dept, resolved FROM fleet
    UNION ALL
    SELECT ticket, agentname, dept, resolved FROM has
    ORDER BY resolved ASC;