W
W
walder2018-12-18 11:21:51
Yii
walder, 2018-12-18 11:21:51

How to build a table where columns are equal to categories?

Hello.
there are tables:
cat_table
Id
name
obj_table
Id
catId
option
count
Maybe someone has met with such a task, you need to make a table to add records to the database, but the columns themselves must be categories, for which I can change the properties and save all records in obj_table.

catId1         | catId2         | catId3
---------------|----------------|---------------
option | count | option | count | option | count

It is not clear how to do this, if an option was selected and a quantity was entered, then when saving, exactly the desired category was sent with what I chose, and if nothing was selected for other categories, they are simply ignored ... well, if it is selected in each, then three records are created.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-12-18
@walder

the usual form, it contains inputs and selects of the form

<select name="catId1[option]">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" name="catId1[value]">

Accordingly, you have an array of type in the controller:
[
catId1 => [option=> 3, value='петя'],
catId2 => [option=> 2, value='Бумбум'],
catId3 => [option=> 1, value='19'],
]

therefore, you iterate through foreach, checking the option and forming a query in the database

P
Pavel Lukin, 2018-12-18
@lukinpe

crosstab will help you .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question