Calendar view...with a difference

Hi,

I would like to produce a calendar like this one:

Is there anybody out there that would know how to do this so that we can produce this dynamically?

Many thanks

It’s not going to be extremely hard, just think about it logically.

First of all, decide whether to do this object-oriented or not. In essence, the year will be an array of month arrays. Each month array will be an array of letters.

Do you have much programming experience? Would you like to tackle this yourself with a nudge or two in the right direction, or are you after some full-on code?

If the former, we (as a forum) would be happy to help. If the latter, I’d recommend posting this as a job in the marketplace - this isn’t a place for people to do your job for you, after all :slight_smile:

Thanks for your reply!

If somebody would like to post the entire code then wonderful!

But I would like to do this myself with a couple of pointers in the right direction.

Unless of course there is something off the shelf that already exists.

Many thanks

It’s just a 2 simple for loops.

Not sure what the A and B is, but the rest is something like this:


$result = array();
for ($month = 1; $month <= 12; $month++) {
  for ($day = 0; $day <= 31; $day++) {
    if (checkdate($month, $day, 2010)) {
      $result[$month][$day] = true;
    }
  }
}
print_r($result);

Expanding on Vali’s very kind example.


<?php
$calendar = array();
for ($month = 1; $month <= 12; $month++) {
  for ($day = 0; $day <= 31; $day++) {
    if (checkdate($month, $day, 2010)) {
      $calendar[$month][$day] = rand(0,2);
    }
  }
}
?>
<html>
    <head>
        <title>Bookings</title>
        <style type="text/css">
        
            table{
                text-align: center;
                background-color: lightgrey;
            }
            
            td{
                padding: 3px;
            }
            
            .status-0{
                color: red;
            }
            
            .status-1{
                color: green;
            }
            
            .status-2{
                color: blue;
            }
        </style>
    </head>
    <body>
        <table>
            <thead>
                <tr>
                    <td>2010</td>
                    <td>1</td>
                    <td>2</td>
                    <td>3</td>
                    <td>4</td>
                    <td>5</td>
                    <td>6</td>
                    <td>7</td>
                    <td>8</td>
                    <td>9</td>
                    <td>10</td>
                    <td>11</td>
                    <td>12</td>
                    <td>13</td>
                    <td>14</td>
                    <td>15</td>
                    <td>16</td>
                    <td>17</td>
                    <td>18</td>
                    <td>19</td>
                    <td>20</td>
                    <td>21</td>
                    <td>22</td>
                    <td>23</td>
                    <td>24</td>
                    <td>25</td>
                    <td>26</td>
                    <td>27</td>
                    <td>28</td>
                    <td>29</td>
                    <td>30</td>
                    <td>31</td>
                </tr>
            </thead>
                <tbody>
                    <?php foreach($calendar as $month_number => $month_days): ?>
                        <tr>
                            <td>
                                <?php echo date('F', mktime(null, null, null, $month_number));?>
                            </td>
                            <?php foreach($month_days as $month_day => $status): ?>
                                <td class="status-<?php echo $status; ?>">
                                    <?php echo $status; ?>
                                </td>
                            <?php endforeach; ?>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
        </table>
    </body>
</html>