Forum Moderators: coopster
Finally I managed to join the queries and make work the calendar Coopster done. Thanks Coopster.
It is an dinamic calendar in which the availability of properties are marked as available or not available.
It works perfect, expect a small detail, that I canīt figure out why...
I get all rows perfectly from table casa and the ones without any bookings in table bookings are correctly marked with an A, and the bookings from table bookings are correctly marked with an N, but I keep getting one extra row, witout any name of property and marked with an N?
Like this.
Property 1 AAAAAAAAAA
Property 2 NNNAAAAAAA
NNNNNNNNNN
Property 3 AAAAAAAAAA
In total should be 10 rows but I get 11.
Everything is correct except the 3rd extra line.
This is the code:
$llegada = '2005-06-01';
list ($lyr, $lmo, $lda) = explode('-', $llegada);
// Build the last day of the month:
$salida = date('Y-m-d', mktime(0,0,0,$lmo+1,0,$lyr));
list ($syr, $smo, $sda) = explode('-', $salida);
$stmt = " SELECT id_propiedad, propiedad, MONTH( llegada ) AS llegadaMonth,
DAY (llegada) AS llegadaDay, MONTH( salida ) AS salidaMonth,
DAY (salida) AS salidaDay FROM casa
LEFT JOIN bookings ON bookings.propiedad = casa.id_propiedad
AND (llegada BETWEEN '$llegada' AND '$salida' OR salida
BETWEEN '$llegada' AND '$salida' OR (llegada <= '$llegada' AND salida >= '$salida'))
WHERE casa.tipo =3
ORDER BY id_propiedad";
$rows = mysql_query($stmt);
$id_propiedad = false;
$calendar = array();
while ($row = mysql_fetch_array($rows)) {
if ($id_propiedad!== trim($row['id_propiedad'])) {
$id_propiedad = trim($row['id_propiedad']);
$calendar[$id_propiedad] = array_fill(1, $sda, 'A');
}
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$propiedad = trim($row['propiedad']);
$calendar[$propiedad][$day] = 'N';
}
}
print "<table>\n";
print "<tr>\n\t<td>Propiedad</td>\n";
foreach (range($lda, $sda) as $day) {
print "\t<td>$day</td>\n";
}
print "</tr>\n";
foreach ($calendar as $id_propiedad => $bookings) {
$bookings = implode("</td>\n\t<td>", $bookings);
print "<tr>\n\t<td>$id_propiedad</td>\n\t<td>$bookings</td>\n</tr>\n";
}
print '</table>';
I been trying to modify this part but of course gives error in the array_fill part.
I thought maybe one could just add the day of the week in this part like this:
$llegada = date("l Y-m-d", mktime(0, 0, 0, 10, 1, 2005));
list ($weekend, $lyr, $lmo, $lda ) = explode('-', $llegada);
// Build the last day of the month:
$salida = date('l Y-m-d', mktime(0,0,0,$lmo+1,0,$lyr));
list ($weekend2, $syr, $smo, $sda) = explode('-', $salida);
Doing that I get an error in this line:
$calendar[$id_propiedad] = array_fill(1, $sda, 'A');
error: Warning: array_fill(): Number of elements must be positive in
But it donīt end here,
The last things
to finalize the calendar:
I want to do as I said in the second post, get the saturdays and sundays to mark that day with an red background color.
And last to add three columns (link to page, zone, and persons to sleep, thought that was going to be easy, but the way the calendar is done I am stuck on that as well.
At the moment I have this, but the $zone and $sleeps donīt work correctly, i.e I get an value printed out, but the same for all rows, not the correct ones:
$llegada = '2005-10-01';
list ($lyr, $lmo, $lda) = explode('-', $llegada);
// Build the last day of the month:
$salida = date('Y-m-d', mktime(0,0,0,$lmo+1,0,$lyr));
list ($syr, $smo, $sda) = explode('-', $salida);
$stmt = " SELECT id_propiedad, propiedad, link_ingles, zona, duermen, MONTH(llegada) AS llegadaMonth,
DAY (llegada) AS llegadaDay, MONTH(salida) AS salidaMonth,
DAY (salida) AS salidaDay FROM casa
LEFT JOIN bookings ON bookings.propiedad = casa.id_propiedad
AND (llegada BETWEEN '$llegada' AND '$salida' OR salida
BETWEEN '$llegada' AND '$salida' OR llegada <= '$llegada' AND salida >= '$salida')
WHERE casa.tipo = 3
order by id_propiedad
";
$rows = mysql_query($stmt);
$id_propiedad = false;
$calendar = array();
while ($row = mysql_fetch_array($rows)) {
$zone = trim($row['zona']);
$sleeps = trim($row['duermen']);
if ($id_propiedad!== trim($row['id_propiedad'])) {
$id_propiedad = trim($row['id_propiedad']);
$calendar[$id_propiedad] = array_fill(1, $sda, '');
}
[/b]if ($row['id_propiedad']== trim($row['propiedad']))[/b] {
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$propiedad = $row['propiedad'];
$calendar[$propiedad][$day] = 'N';
}
}
}
print "<table>\n";
print "<tr>\n\t<td>Propiedad</td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n";
foreach (range($lda, $sda) as $day) {
print "\t<td>$day</td>\n";
}
print "</tr>\n";
foreach ($calendar as $id_propiedad => $bookings) {
$bookings = implode("</td>\n\t<td>", $bookings);
$id_propiedad= str_replace("_", " ", $id_propiedad);
print "<tr>\n\t<td>$id_propiedad</td>\n\t\n\t<td>$zone</td>\n\t\n\t<td>$sleeps</td>\n\t<td>$bookings</td>\n</tr>\n";
}
print '</table>';
properties * ** 1 2 3 4 5 etc
property11 M 6 N N N N N
property12 MC 5 A A A A A
property13 PB 6 N N A A A
all properties booked and not booked: id_propiedad (property) *$zone, $sleeps, $link from table casa
table bookings (propiedad, llegada, salida) joined to get the bookings to mark with an N.
DAYOFWEEK(date)Returns the weekday index for
date(1 = Sunday, 2 = Monday, ..., 7 = Saturday).[dev.mysql.com...]
Just add a new column to your query and check it during the loop which builds the <td> for each day. If it is a 1 or a 7, you can change it's color by adding a class to the <td>.
[edited by: coopster at 9:37 pm (utc) on Sep. 7, 2005]
Though in case of october day 1 and 2 are saturdays and sundays.
And the days in the array (in the calendar) are not dates, or are they?
As I understand they are just an number between 1 and last day in the month.
Maybe I could put:
If 2005-10-$booking = 1 or 2 then etc.?
If it was a way to figure out which number of day in the month are saturdays and sundays, yes.
We will have to do the work within the loop which builds the <td> of days, without any help here from MySQL. Simply modify the loop which builds the <td>'s. Do you want to highlight the column heading, which is the day numbers?
foreach (range($lda, $sda) as $day) {
$class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td$class>$day</td>\n";
}
But Now I already have the days for saturday and sunday in var $class.
So could I just donīt use it in the next loop?
something like:
if (in_array($bookings = $class )) { echo "<td class='weekend'>"; }
Actually I ever worked with arrays, only used php to display tables from mysql, calculate etc.,
so itīs complicated.
But I am not certain that $bookings contains only an number or not.
Array
(
[1] => N
[2] => N
[3] => N
[4] => N
[5] => A
[6] => A
[7] => A
[8] => N
[9] => N
...
For future reference, dumping an array to the browser is extremely helpful when programming. This is how you can do that:
foreach ($calendar as $propiedad => $bookings) {
print '<pre>'; print_r($bookings); print '</pre>';
exit;
... I often use exit to stop processing and have a look at where I'm at. That's how I printed the array you see here.
Now, you know you aren't crazy at all, and very close with a solution! The days for Saturday and Sunday are not in the variable $class though, it is only used to determine whether or not that particular day is a weekend day and then cleared if not. We can make a new array with that data though and use it in the next loop as you suggested:
$weekends = array(); // initialize
foreach (range($lda, $sda) as $day) {
$class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td$class>$day</td>\n";
// Populate an array with the weekend dates:
if ($class) {
$weekends[] = $day;
}
}
print "</tr>\n";
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend];
}
$bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
print "<tr>\n\t<td>$propiedad</td>\n\t$bookings\n</tr>\n";
}
'#WEEKEND#'that we can search and replace later.
This is nearly finished, the last to do, is to add
SELECT id_propiedad, propiedad, link_ingles, zona, duermen,
The problem is to display them, I canīt use $row[zona]that I normally use, though the while ($row = mysql_fetch_array($rows)) {
is closed.
So I tried to do:
$link = trim($row['link_ingles']);
$zone = trim($row['zona']);
$sleeps = trim($row['duermen']);
and to display print "<tr>\n\t<td>$propiedad</td>\n\t<td>$zone</td>
That is to put an link for the property and 2 columns with information.
But donīt work, displays same result for all rows, suppose the first one it finds, though &id_propiedad is in an array.....I am beginning to hate them :)
So I suppose I need to asociate those columns to this:
$calendar[$id_propiedad] = array_fill(1, $sda, '');
This is the last thing to do,
Billions of thanks, you donīt know what this means to me,
the actual availaty-pages I have whas an workaround that brings me lot of work and headache.
I will need time to understand it though
I'll try to explain with some examples ...
In September of 2005 we know that dates 3 and 4 are a weekend. The date('w') checks each day sequentially and returns that for us -- we see if the day is either a 0 = Sunday or a 6 = Saturday. If so, we set the class to "weekends" for the dates over the top (the 1 2 3 4 ... 30).
$class = (in_array [php.net](date [php.net]('w', mktime [php.net](0, 0, 0, $lmo, $day, $lyr)), array [php.net](0, 6))) ? ' class="weekend"' : '';
Next, we add that index number (which happens to be the dates) to our "weekends" array to use in the next step.
if ($class) {
$weekends[] = $day;
} The next loop is the workhorse. It is simply taking each property and finding the "weekends" indexes for each property's $bookings. It then modifies that date's value by setting it up with a little indicator for us, #WEEKEND#:
Array
(
[1] => N
[2] => N
[3] => #WEEKEND#N
[4] => #WEEKEND#N
[5] => A
[6] => A
[7] => A
[8] => N
[9] => N
...
Now when we implode that array into a string we can use a regular expression to find the #WEEKEND# values we setup and change them to get them wrapped inside our <td> element with the new "class" attribute.
The string starts out like the first line and ends like the second, after we use the preg_replace() regular expression to make our desired changes ...
<td>N</td>\n\t<td>N</td>\n\t<td>#WEEKEND#N</td>\n\t<td>#WEEKEND#N</td>\n\t<td>A</td>...
<td>N</td>\n\t<td>N</td>\n\t<td class="weekend">N</td>\n\t<td class="weekend">N</td>\n\t<td>A</td>...
I need to absorb the latter half of your post to see if I can understand what you are getting at ...
$calendar = array();
$property = array();
while ($row = mysql_fetch_array($rows)) {
if ($propiedad!== trim($row['propiedad'])) {
$propiedad = trim($row['propiedad']);
$calendar[$propiedad] = array_fill(1, $sda, 'A');
$property[$propiedad]['link'] = trim($row['link_ingles']);
$property[$propiedad]['zone'] = trim($row['zona']);
$property[$propiedad]['sleep'] = trim($row['duermen']);
}
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$calendar[$propiedad][$day] = 'N';
}
}
Now to add the links and new data, just modify the printing of the property-specific information in the last loop:
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend];
}
$bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
$link = $property[$propiedad]['link'];
$zone = htmlentities [php.net]($property[$propiedad]['zone']);
$sleep = htmlentities($property[$propiedad]['sleep']);
print "<tr>\n\t<td><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
print "\n\t<td>$zone</td>\n\t<td>$sleep</td>\n\t$bookings\n</tr>\n";
} There are two similar vars, one is $propiedad that only gets the bookings (the N) from table bookings,
the other is $id_propiedad from table casa that gets all properties (not booked at all as well) and the aditional information.
As you can see, sometimes in the loops it says $propiedad and sometimes $id_propiedad, depending on from which table we get the dates.
This is the last code, which I modified with the new changes, changes in black, note I changed $propiedad to $id_propiedad as I think it should be.
Adding the new code and changing it to $id_propiedad I get the same property, link, zone, sleep in all rows.
$calendar = array();
$property = array();
while ($row = mysql_fetch_array($rows)) {
if ($id_propiedad!== trim($row['id_propiedad'])) {
$id_propiedad = trim($row['id_propiedad']);
$calendar[$id_propiedad] = array_fill(1, $sda, '');
$property[$id_propiedad]['link'] = trim($row['link_ingles']);
$property[$id_propiedad]['zone'] = trim($row['zona']);
$property[$id_propiedad]['sleep'] = trim($row['duermen']);
}
if ($row['id_propiedad']== trim($row['propiedad'])){
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$propiedad = $row['propiedad'];
$calendar[$propiedad][$day] = 'N';
}
}
}
print "<table>\n";
print "<tr>\n\t<td>Propiedad</td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n";
$weekends = array(); // initialize
foreach (range($lda, $sda) as $day) { $class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td$class>$day</td>\n";
// Populate an array with the weekend dates:
if ($class) { $weekends[] = $day; } }
print "</tr>\n";
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' .
$bookings[$weekend]; } $bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
$link = $property[$id_propiedad]['link'];
$zone = htmlentities($property[$id_propiedad]['zone']);
$sleep = htmlentities($property[$id_propiedad]['sleep']);
print "<tr>\n\t<td><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
print "\n\t<td>$zone</td>\n\t<td>$sleep</td>\n\t$bookings\n</tr>\n";
}
print '</table>';
And this is the last code that works without adding the last modifications:
$rows = mysql_query($stmt);
$id_propiedad = false;
$calendar = array();
while ($row = mysql_fetch_array($rows)) {
if ($id_propiedad!== trim($row['id_propiedad'])) {
$id_propiedad = trim($row['id_propiedad']);
$calendar[$id_propiedad] = array_fill(1, $sda, '');
}
if ($row['id_propiedad']== trim($row['propiedad'])){
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$propiedad = $row['propiedad'];
$calendar[$propiedad][$day] = 'N';
}
}
}
print "<table>\n";
print "<tr>\n\t<td>Propiedad</td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n";
$weekends = array(); // initialize
foreach (range($lda, $sda) as $day) { $class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td$class>$day</td>\n";
// Populate an array with the weekend dates:
if ($class) { $weekends[] = $day; } }
print "</tr>\n";
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) { $bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend]; } $bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
print "<tr>\n\t<td>$propiedad</td>\n\t$bookings\n</tr>\n";
}
print '</table>';
id_propiedadand
propiedad, which tells me they are the same value. Therefore, why return them both in your query? If there are no bookings for one any of them, the other columns will be returned as NULL and the entire month will be open.
Summary:
Use the logic layed out, no modifications. Update your query.
$stmt = "
SELECT
id_propiedad AS propiedad,
link_ingles,
zona,
duermen,
MONTH(llegada) AS llegadaMonth,
DAY (llegada) AS llegadaDay,
MONTH(salida) AS salidaMonth,
DAY (salida) AS salidaDay
FROM casa
LEFT JOIN bookings ON (casa.id_propiedad = bookings.propiedad)
WHERE
(
(llegada BETWEEN '$llegada' AND '$salida')
OR
(salida BETWEEN '$llegada' AND '$salida')
)
AND
casa.tipo = 3
ORDER BY id_propiedad, llegada
";
I don't quite understand why you had the LEFT JOIN the way you did but if I understand the table layouts correctly you want to join on "propiedad". Table order doesn't matter in the ON clause, but I prefer to always work from left to right, easier to read.
I moved some of the JOIN syntax into the WHERE clause, which really is it's rightful home. We aren't joining on the monthly criteria, merely reducing our result set based on it. Therefore it is common practice to keep it in the WHERE clause. I also added some parenthesis around the WHERE clause to distinguish more clearly what we want to happen. SELECT WHERE (the start date is in this month OR where the end date is in this month) AND where the casa.tipo = 3.
Lastly, I added the llegada to the ORDER BY clause again. Property will be first sort order, then, when there are bookings we will get the bookings in date order. I guess it really doesn't matter, you could drop the "llegada" and it won't make a difference because of the way we are handling the logic anyway. Plus, if you don't have an index over that table by "llegada" you wouldn't have to create one. Go ahead and drop "llegada" from the ORDER BY clause. and just sort by property.
ORDER BY id_propiedad
anyway I past the code for you so you can check it is the first code you did with the addings.
$stmt = " SELECT id_propiedad as propiedad, link_ingles, zona, duermen, MONTH(llegada) AS llegadaMonth,
DAY (llegada) AS llegadaDay, MONTH(salida) AS salidaMonth,
DAY (salida) AS salidaDay FROM casa
LEFT JOIN bookings ON bookings.propiedad = casa.id_propiedad
AND (llegada BETWEEN '$llegada' AND '$salida' OR salida
BETWEEN '$llegada' AND '$salida' OR llegada <= '$llegada' AND salida >= '$salida')
WHERE casa.tipo = 3
order by id_propiedad
";
$rows = mysql_query($stmt);
$propiedad = false;
$calendar = array(); $property = array();
while ($row = mysql_fetch_array($rows)) {
if ($propiedad!== trim($row['propiedad'])) {
$propiedad = trim($row['propiedad']);
$calendar[$propiedad] = array_fill(1, $sda, 'A');
$property[$propiedad]['link'] = trim($row['link_ingles']);
$property[$propiedad]['zone'] = trim($row['zona']);
$property[$propiedad]['sleep'] = trim($row['duermen']);
}
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$calendar[$propiedad][$day] = 'N';
}
}
print "<table>\n";
print "<tr>\n\t<td>Propiedad</td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n";
$weekends = array(); // initialize
foreach (range($lda, $sda) as $day) { $class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td$class>$day</td>\n";
// Populate an array with the weekend dates:
if ($class) { $weekends[] = $day; } }
print "</tr>\n";
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend];
}
$bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
$link = $property[$propiedad]['link'];
$zone = htmlentities($property[$propiedad]['zone']);
$sleep = htmlentities($property[$propiedad]['sleep']);
print "<tr>\n\t<td><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
print "\n\t<td>$zone</td>\n\t<td>$sleep</td>\n\t$bookings\n</tr>\n"; }
print '</table>';
I have it, correct or not no idea,
up to you to critize it,
but seems to work..
So hopefully I donīt have to "bother" you any more.
I am so pleased.
Thanks again and again.
This is what I ended with,
my select, changing it using alias,
and modifying the first 2 loops, adding an 3rd.
$stmt = " SELECT id_propiedad as propiedad, propiedad as test, link_ingles, zona, duermen, MONTH(llegada) AS llegadaMonth,
DAY (llegada) AS llegadaDay, MONTH(salida) AS salidaMonth,
DAY (salida) AS salidaDay FROM casa
LEFT JOIN bookings ON bookings.propiedad = casa.id_propiedad
AND (llegada BETWEEN '$llegada' AND '$salida' OR salida
BETWEEN '$llegada' AND '$salida' OR llegada <= '$llegada' AND salida >= '$salida')
WHERE casa.tipo = 3
order by id_propiedad
";
$rows = mysql_query($stmt);
$propiedad = false;
$calendar = array(); $property = array();
while ($row = mysql_fetch_array($rows)) {
if ($propiedad!== trim($row['propiedad'])) {
$propiedad = trim($row['propiedad']);
$calendar[$propiedad] = array_fill(1, $sda, 'A');
$property[$propiedad]['link'] = trim($row['link_ingles']);
$property[$propiedad]['zone'] = trim($row['zona']);
$property[$propiedad]['sleep'] = trim($row['duermen']);
}
if ($row['propiedad']!== trim($row['test'])){
$propiedad = trim($row['propiedad']);
$calendar[$propiedad] = array_fill(1, $sda, 'A');
}
elseif ($row['propiedad']== trim($row['test'])){
$begin = ($row['llegadaMonth'] == $lmo)? $row['llegadaDay'] : 1;
$end = ($row['salidaMonth'] == $lmo)? $row['salidaDay'] : $sda;
foreach (range($begin, $end) as $day) {
$calendar[$propiedad][$day] = 'N';
}
Now I have trouble putting the css classes...
I have this css:
.casa1 {etc}
.weekend { background-color: #FF6633; }
.availability {etc}
I need to add .availability to $bookings, $bookings donīt have any <td> in the print and already have an class in this line:
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
And I canīt put it in the <tr> though $propiedad have another class.
So where to put the second class for $ bookings.
This is the very very last and the calendar is finished.
Been trying in all places but nothing....
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend];
}
$bookings = '<td>' . implode("</td>\n\t<td>", $bookings) . '</td>';
$bookings = preg_replace("/<td>#WEEKEND#/", '<td class="weekend">', $bookings);
$link = $property[$propiedad]['link'];
$zone = htmlentities($property[$propiedad]['zone']);
$sleep = htmlentities($property[$propiedad]['sleep']);
$propiedad = str_replace("_", " ", $propiedad);
print "<tr >\n\t<td class='casa1'><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
print "\n\t<td class='availability'>$zone</td>\n\t<td class='availability'>$sleep</td>\n\t $bookings\n</tr>\n"; }
print '</table>';