A
A
Anton Myasnov2019-10-05 21:13:23
PHP
Anton Myasnov, 2019-10-05 21:13:23

How to work with this data obtained from the DB table?

Good day. In MODX, using a self-made snippet, I get data from a table in the database.
Purpose: to display data in the form of a list on the site. In php and sql, a complete zero, and in Google, I clearly formulate the task incorrectly.
Here is the snippet code:

<?php
$sql = "SELECT day, clerk_name, day_shift, night_shift
      FROM animal_schedules
      JOIN animal_clerks USING (id_clerk)
      WHERE day >= '2019-10-05'
      ORDER BY day, status, clerk_name";
    foreach ($modx->query($sql) as $animal) {
    echo '<li>  <p class="timetable-date">'.$animal['day'].'<p class="timetable-doctors"><span>'.$animal['clerk_name'].'</span></p><li>';
                                              }

I need to generate a schedule and display it. But now the date is displayed, under which the name of the person and then a new line with the same date but a new person, and so on until the dates run out.
1) A table of such a plan. day - date of person change. id_clerks, status, day_shift, night_shift
The day field can have multiple entries for the same day. That is, if 3 people work that day, then 3 records will be the same, but the id_clerks field will be different. Is it possible to group (group by simply displays the date once and all the others disappear along with the person) so that the date is displayed alone but all people working on that day are displayed? I assume that then foreach will need to be changed to something else.
2) Or is it possible to somehow put all the data that comes in some kind of object, so that we can take the necessary fields from it and how to do it? Or save to the ModX resource with which it will be easier to work with?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question