从2个单独的mysql表中提取数据,在同一个表行上回显匹配记录

时间:2018-02-04 00:01:46

标签: php mysql

我有两个MySQL表,一个用于存储盒号,另一个用于保存每个盒子的内容。在我以前将这一切保存在一个表上之前,例如第1列=框号,第2列=以逗号分隔格式的框内容,我现在有表' move_items'第1列=框号,表格' move_contents'第1列=框号,表格' move_contents'第2列=框内容。

我现在发现的问题是,虽然我可以在<table>中回显结果,但我会为包含多个内容的同一个框获取单独的行:

enter image description here

我想要的是,如果第2号盒子包含2个项目,我希望这只在一行中显示两个项目的内容&#39;柱:

enter image description here

我目前的查询是:

$sql = "SELECT move_items.*, move_contents.* FROM move_items LEFT JOIN move_contents ON move_items.boxnumber = move_contents.box ORDER BY move_items.date DESC";  
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)) {
    echo '<tr>
        <td>'.$row["boxnumber"].'</td>
        <td>'.$row["boxcontents"].'</td>
    </tr>';
}

我现在完全失去了。在我回到以旧的低效方式将所有盒子内容存储在一个逗号分隔的单元格中之前,有人可以帮助我吗?我尝试过很多像GROUP BY这样的东西,但是我的经验不足。

1 个答案:

答案 0 :(得分:2)

您正在寻找class Compile_Import { public static string getargs = null; private static StreamReader sr; public static void CompileAndRun(FileInfo importInfo, string args) { getargs = args; if(importInfo.Extension == ".cbe" && importInfo.Exists) { sr = new StreamReader(importInfo.FullName); //Where my problem occurs. string curlinecont = null; while((curlinecont = sr.ReadLine()) != null) { string RawToken = Parser.Parse.ParseLineIntoToken(Run.Stats.CurrentLineContents); Token_Management.Process_Token.ActOnToken(RawToken); } } } group by

group_concat