M
M
Mikha Pankratov2016-08-31 11:57:04
MySQL
Mikha Pankratov, 2016-08-31 11:57:04

Is it worth switching to another data storage?

Good afternoon,
I’m struggling with the issue of storage,
I store the time frame
from to
days from to
Before it was like this - we chose the time interval from 1am to 6pm and days Mon-Fri
And everything was stored in one line, as a result, the output every day from 1am to 6pm except Sat Sun
now the customer wants all days except the last to 12.00 in this case, I'm thinking whether to store it in different lines. In general, how to get by with little blood ....?
The problem is actually in order to display all days except the last one with an interval of
Mon from 1am to 00.00
Tue from 1am to 00.00
Wed from 1am to 00.00
Thu from 1am to 00.00
Fri from 1am to 6pm

if ($results = self::find()->where(['user_id' => $user_id])->all()) {
            foreach ($results as $key => $result) {
                if(!is_null($result->from_day_id)){
                    if ($result->from_day_id == $result->to_day_id) {
                        $this->data[$result->from_day_id][] = ['from' => $result->fromTime->time, 'to' => $result->toTime->time];
                    } else {
                        $n = $result->from_day_id;
                        $m = $result->to_day_id;
                        $i = $n - 1;
                        do {
                            $d = $i % 7 + 1;
                            $this->data[$d][] = ['from' => $result->fromTime->time, 'to' => $result->toTime->time];
                            $i++;
                        } while ($d != $m);
                    }
                }
            }
        }

        if (!empty($this->data)) {
            return $this->uniqueUserA($this->data);
        }

So I think it's better to re-chemize the script or store it differently ...

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