简体   繁体   English

mysql多表查询返回排序结果后再发送查看

[英]mysql multi table query return sort results before sending to view

I'm busy creating site to control the flow of documents. 我正忙于创建站点来控制文档流。 I have the following tables 我有下表

Drawings 图纸 在此处输入图片说明

Drawing revision 图纸修订 在此处输入图片说明

Transmittal slip 透射滑 在此处输入图片说明

Client 客户 在此处输入图片说明

Project details 项目详情 在此处输入图片说明

In my site the user can select the documents that they want to send the client and to which clients it should be going to. 在我的站点中,用户可以选择要发送给客户端的文档以及文档应该发送给哪些客户端。 The site should then present this in a view where the slip number, date, client and project info is presented once at the top of the page with the documents that are being sent to that client placed in a html table below this. 然后,该网站应在视图中显示此清单编号,日期,客户和项目信息,在页面顶部一次显示一次,并将发送给该​​客户的文档放置在该页面下方的html表中。

I created the following query. 我创建了以下查询。

SELECT tr.*, d.*, dr.*, cl.*, us.*, proj.project_name 
FROM transmittal_slips AS tr 
   INNER JOIN drawings AS d ON tr.dwg_id = d.dwg_id 
   INNER JOIN dwg_rev AS dr ON d.dwg_id = dr.dwg_id 
   INNER JOIN client AS cl ON tr.client_id = cl.client_id 
   INNER JOIN `user` AS us ON tr.user_id = us.id 
   INNER join projects AS proj ON tr.project_no = proj.project_no 
 WHERE tr.slip_num = '".$slip_num."' AND dr.slip_num = '".$slip_num."'   
 ORDER BY cl.client_id"

My query joins all the tables and in Codeigniter gives it back to me a numeric array which I can pass to the view, but which I would then need to filter the array to get the display I want as described above. 我的查询连接了所有表,并在Codeigniter中将其返回给我一个数值数组,可以将其传递给视图,但是如上所述,我将需要过滤该数组以获取所需的显示。

This is the current display that is produced with a foreach loop and some tags and an html table. 这是使用foreach循环,一些标签和html表生成的当前显示。 在此处输入图片说明

This is the way that I want the data displayed. 这是我要显示数据的方式。 在此处输入图片说明

How do I filter or sort the results per client before passing it to the view so I can get the view to display the slip number, date, client info, etc once with the documents listed below this. 在将每个客户的结果传递到视图之前,我该如何对其进行过滤或排序,这样我就可以使用下面列出的文档使视图一次显示发票编号,日期,客户信息等。 I suppose you could compare what I want to do to an invoice from an online store such as amazon. 我想您可以将我想做的事情与亚马逊等在线商店的发票进行比较。

Please help somebody 请帮助某人

It looks like you have some header information that is the same for all rows, and then some data that is different for each row. 看起来您具有一些对于所有行都相同的标头信息,然后对于每个行而言都具有一些不同的数据。 If you want to be formal about it, after the query, you can do something like: 如果要对此进行正式化,在查询后,可以执行以下操作:

$header = rows[0];
$list = array_map(function($row) { return array('dwg_id' => $row->dwg_id, ...); }, $rows);

but really all you need to do in the view is first render your header based on a single row, then loop through all the rows and cherry-pick the fields you need. 但实际上,您在视图中所需要做的就是首先基于一行显示标题,然后遍历所有行并挑选所需的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM