A
A
Alex Ershov2015-06-08 14:04:23
MySQL
Alex Ershov, 2015-06-08 14:04:23

How can rows of one table be represented by columns of another?

There is a table Goods

id_good | name
1         good1
2         good2

There is a Warehouses table
id_stage |  name | status
1         stage1      1
2         stage2      1

There is a table GoodsOn the Warehouses (in which warehouses the goods are in the number of pieces)
id_stage | id_good | count
1          1          34
2          2          77

As a result, I need to build a table that will display the quantity of goods in active warehouses
good  | stage1 | stage2
good1    34          0
good2    0            77

Questions:
1. Tell me how to make such a dataprovider for gridview?
The difficulty for me arises precisely in making such a query in which there would be stage1 (and other active stages) as columns.
2. Is it necessary to pass only the dataprovider to the gridview, or is it possible to somehow pass an already formed array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-06-08
@Nipheris

I'll try to ask you the direction
en.wikipedia.org/wiki/Pivot_table
stackoverflow.com/questions/7674786/mysql-pivot-table

M
Maxim Timofeev, 2015-06-08
@webinar

Make a separate model that may not have its own table in the database, make links to the necessary tables in it and use the DataProvider from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question