Forum Moderators: coopster

Message Too Old, No Replies

validate availbilitycalendar

         

helenp

7:26 pm on Aug 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi, with this calendar a moderator helped me, or better said did it, as its very complicated. This was some years ago.
I ever validated it, now I am changing to xhtml transitional from html transitional, and are using w3 validator.
Well, the page with the calendar in html gets only 1149 errors....and in xhtml gets the small amount of 3422 Errors.
Have not checked all, but as the result is a table with result from a database, I think nearly all are the same issue.
This is the main error I get:
- end tag for element "td" which is not open <th>N</td>
- document type does not allow element "th" here <th>N</td>
These 2 errors comes over and over again.
When I check the page with dreamweavers w3checker I get 0 errors (however there is no databaseresult there).
And as far as I can see there arent anything like this in the code <th>N</td>, N means not available and is a result given from the database, su I suppose that is what is given when the result comes. Honestly the code is to complicated for me to understand.
This is the phpcode:

$llegada = '2011-08-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 as propiedad, tiporeserva, 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 = 'villa'
order by id_propiedad
";
$result = mysql_query($stmt);
$propiedad = false;
$calendar = array(); $property = array();
while ($row = mysql_fetch_object($result)) {
if ($propiedad!== trim($row->propiedad)) {
$propiedad = trim($row->propiedad);
$calendar[$propiedad] = array_fill(1, $sda, '');
$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, '');

}
elseif ($row->propiedad== trim($row->test)){
$larga = ($row->tiporeserva);
$begin = ($row->llegadaMonth == $lmo)? $row->llegadaDay : 1;
$end = ($row->salidaMonth == $lmo)? $row->salidaDay : $sda;
foreach (range($begin, $end) as $day) {
$calendar[$propiedad][$day] = 'N';
if ($larga=="larga") {
$calendar[$propiedad][$day] = 'L'; }
}
}
}


?><div align="center">
<?php
print "<table class='availability'>\n";
print "<tr> \n";
print"<th class='ancho127' colspan='34'> <p>Villas 3-5 bedrooms <span class='style1'>(8-14 persons)</span> <br />
</p></th>\n";
print"</tr> \n";
print "<tr>\n\t<td></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 = '<th>' . implode("</td>\n\t<th>", $bookings) . '</th>';
$bookings = preg_replace("/<th>#WEEKEND#/", '<th 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<th>$sleep</th>\n\t<th>$zone</th>\n\t $bookings\n</tr>\n"; }
print "<tr>\n\t<td></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";
print '</table><br /><br />';
?></div>



Also a smaller thing is that the database is not in utf=8 so in the connection I added mysql_query ("SET NAMES 'utf8'");
This works perfect on other pages, and also in other scripts with results from the database in the same page, however it does not work in the availabilitycalendar....the spanish ñ I get strange characters.

If somebody pleas have a clue what to do to validate it.
Thanks in advance.

helenp

11:14 pm on Aug 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Debugging,
The error is on this line;
Eliminating this;
$bookings = '<th>' . implode("</td>\n\t<th>", $bookings) . '</th>'; (the script stops to work)
but I get thousands of less errors lol.


Uups, I fixed it by myself, changing the td to th on that line.
So now only remain the "bug" with characters, just cant understand it.

This is the only problem with the calendar now:
The database is not in utf=8 so in the connection I added mysql_query ("SET NAMES 'utf8'");
This works perfect on other pages, and also in other scripts with results from the database in the same page, however it does not work in the availabilitycalendar....the spanish ñ I get strange characters.
Must be some function or something else in the script that makes it, as every other mysql results works perfect with set names.

I have tried str_replace, and added this header("Content-type:text/html; charset=utf-8");
and nothing works :(

helenp

9:02 am on Aug 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Think I got it, however dont know if is a good solution:
On this line:
print "<tr>\n\t<td class='casa1'><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
If i delete htmlentities I get the spanish ñ correctly.

The strange is If I have as character in the meta utf-8 and dont change anything, the characters in the calendar are correct. However the other scripts that comes from the database get the character wrong.
However if I add this to my connection:
mysql_query ("SET NAMES 'utf8'");
The calendars character are bad, but other scripts are ok,
so I suppose the htmlentities makes the same thing and is not needed in this script anymore....before it was html and iso=8859=1

As you can see I have it in 3 places, however its the print that gives me the bad character.
$zone = htmlentities($property[$propiedad]['zone']);
$sleep = htmlentities($property[$propiedad]['sleep']);
print "<tr>\n\t<td class='casa1'><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";

Should I delete all htmlentities? Or is there any better solution?

Reading php net, and in that function somebody says:
"under what circumstances would someone want a ntilde [ñ] to be converted into "ñ" as htmlentities does?
the correct method of translation should return the accurate NCR for the multibyte unicode sequence
which in this case is &#241;" and after a long code that I dont understand.