我看了一下,我真的很想知道如何克服这个问题。我已经看过UNION/UNION ALL
和JOIN
了,但是我无法正常工作。
基本上,我有来自三个MySQL表的数据。这三个表具有来自其的表单数据,并分别被命名为Fleet,Facilitys,HAS。数据具有相似的头,但信息不同。它们都共享相同的4个标头:ticket | agentname | dept | resolved
。
我有以下PHP代码在HTML表格中显示此内容,但无法从所有三个表格中显示它。 (我只能发布两个图像)
$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和Google中学到了什么。请尽可能解释您的答案。
最佳答案
您有语法错误:ORDER BY ASC解决了,应该是:ORDER BY resolve ASC
您是否尝试在选择中指定列?尝试这样的事情:
SELECT ticket, agentname, dept, resolved FROM fleet
UNION ALL
SELECT ticket, agentname, dept, resolved FROM has
ORDER BY resolved ASC;
关于php - 从PHP中的三个MySQL表中选择数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44920358/