0

I have an array with shops and working hours like this:

[0] => Array
(
[name] => Value1

[working_hours] => Array
            (
                [sunday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 6:00
                            )

                    )

                [saturday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 6:00
                            )

                        [1] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

                [tuesday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 4:00
                            )

                        [1] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

                [friday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 4:00
                            )

                        [1] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

                [thursday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 4:00
                            )

                        [1] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

                [wednesday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 00:00
                                [1] => 4:00
                            )

                        [1] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

                [monday] => Array
                    (
                        [0] => Array
                            (
                                [0] => 19:30
                                [1] => 23:59
                            )

                    )

            )

This is one record of the hundreds that I have to insert into db. I' ve made my bd table like this: hours_id INT, shop INT, day INT or VARCHAR(no problem), openTime TIME, closeTime TIME. So far my code is something like that: ...//code here

foreach ($row["hours"] as $h1) {
      $day = $h_days["?"]; //how to put it here?
      foreach ($h1 as $h2) {
        foreach ($h2 as $hour) {
            $openTime = $hour["0"];
            $closeTime = $hour["1"];
            $insert_items4 = mysql_query("INSERT INTO hours (shop, day, openTime, closeTime) VALUES ('".$var1."', '". $day."', '".$openTime."', '".$closeTime."')");

        }
      }
    }    

I found some examples with array_map like this $days = array_map('mysql_real_escape_string', array_values($row["hours"])); or something like this $keys = implode(', ', array_keys($row["hours"])); but i don't know how to use them exactly. How can I insert the days of each record with their open and close time? I searched but I can't find something like this. Thanks in advance

arek
  • 1
  • 6
  • Yes that was too obvious for the key. Thank you very much. But my problem also is that with this I can't get the right time. Should I change the type of column from TIME to VARCHAR? – arek May 02 '17 at 13:02
  • It depends on what you need. Take a look at the [definition](https://dev.mysql.com/doc/refman/5.5/en/date-and-time-type-overview.html) and decide if that's what's right for you. – aynber May 02 '17 at 13:12

0 Answers0