Answer the question
In order to leave comments, you need to log in
How to arrange the data in the table?
There is an entry in the database:
name: Ivan
Day: Tuesday
Project: 1
name: Gennady
Day: Saturday
Project: 2
How can I enter this data into the table, what would happen:
My code:
<table class="table">
<thead>
<tr>
<th scope="col">Проект</th>
<th scope="col">Пн</th>
<th scope="col">Вт</th>
<th scope="col">Ср</th>
<th scope="col">Чт</th>
<th scope="col">Пт</th>
<th scope="col">Сб</th>
<th scope="col">Вс</th>
</tr>
</thead>
{% for user in users %}
<tbody>
<tr>
<th scope="row">{{ user.project }}</th>
Тут нужно добавить код...
</tr>
</tbody>
{% endfor %}
</table>
Answer the question
In order to leave comments, you need to log in
You can solve this problem with a database:
select
projects.id,
GROUP_CONCAT(if(day=1, name, null)) as Monday,
GROUP_CONCAT(if(day=2, name, null)) as Tuesday,
GROUP_CONCAT(if(day=3, name, null)) as Wednesday,
GROUP_CONCAT(if(day=4, name, null)) as Thursday,
GROUP_CONCAT(if(day=5, name, null)) as Friday,
GROUP_CONCAT(if(day=6, name, null)) as Saturday,
GROUP_CONCAT(if(day=7, name, null)) as Sunday
from projects
group by projects.id
;
+====+========+=========+===========+==========+========+==========+========+
| id | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday |
+====+========+=========+===========+==========+========+==========+========+
| 1 | John | | | | | | |
+----+--------+---------+-----------+----------+--------+----------+--------+
| 2 | | | | Jack,Mike| | | |
+----+--------+---------+-----------+----------+--------+----------+--------+
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question