Page 1 of 1
broken html
Posted: Mon Aug 27, 2007 12:09 pm
by billinnc
I'm new to building web sites using PHP and MySQL.
This problem has been frustrating me for about a week...
I am trying to output several hundred rows of database output to a HTML table. Everything seems to work OK... unless I view the site from work (connected through a proxy server) -- the table seems mostly OK, but occasionally a TD or TR tag is written without a open or close bracket. This doesn't happen when I view the site from home.
This happens randomly in different parts of the page. The more data are output to the page, the more likely the site is to improperly display the data. Every time I refresh the site, the errors are in different places.
Here is what I've tried so far...
1. Turned on output buffering in the PHP code with
and end with
2. Attempted to control the http header with php code so as to not allow the proxy to cache the site (as follows)
Code: Select all
header("Cache-Control: must-revalidate");
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
Other details...
web server: apahce, hosted with godaddy
php: version 4.3.11
thanks, Bill
Posted: Mon Aug 27, 2007 12:14 pm
by miro_igov
Maybe issue in your php code. Post it please.
Posted: Mon Aug 27, 2007 12:20 pm
by billinnc
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
here it is...
Code: Select all
<table>
<tr>
<td>date</td>
<td>ac</td>
<td>model</td>
<td>tot</td>
<td>ac</td>
<td>nt</td>
<td>nvg</td>
<td>act</td>
<td>sim</td>
<td style="width: 2%">A</td>
<td style="width: 2%">B</td>
<td style="width: 2%">1</td>
<td style="width: 2%">2</td>
<td>purpose</td>
<td>TR</td>
</tr>
<?php
$i=0;
while ($i < $num) {
$ID=mysql_result($result,$i,"ID");
$date=mysql_result($result,$i,"date");
$aircraft=mysql_result($result,$i,"aircraft");
$model=mysql_result($result,$i,"model");
$tot=mysql_result($result,$i,"tot");
$ac=mysql_result($result,$i,"ac");
$nt=mysql_result($result,$i,"nt");
$nvg=mysql_result($result,$i,"nvg");
$act=mysql_result($result,$i,"act");
$sim=mysql_result($result,$i,"sim");
$app_a=mysql_result($result,$i,"app_a");
$app_b=mysql_result($result,$i,"app_b");
$app_1=mysql_result($result,$i,"app_1");
$app_2=mysql_result($result,$i,"app_2");
$purpose=mysql_result($result,$i,"purpose");
$tr=mysql_result($result,$i,"tr");
echo "\n <tr> \n\t <td><a href=\"flighttime_detail.php?id=";
echo $ID;
echo "\">";
echo $date;
echo "</a></td> \n ";
echo "\t <td> ";
echo $aircraft;
echo " </td> \n";
echo "\t <td> ";
echo $model;
echo " </td> \n";
echo "\t <td> ";
echo $tot;
echo " </td> \n";
echo "\t <td> ";
echo $ac;
echo " </td> \n";
echo "\t <td> ";
echo $nt;
echo " </td> \n";
echo "\t <td> ";
echo $nvg;
echo " </td> \n";
echo "\t <td> ";
echo $act;
echo " </td> \n";
echo "\t <td> ";
echo $sim;
echo " </td> \n";
echo "\t <td> ";
echo $app_a;
echo " </td> \n";
echo "\t <td> ";
echo $app_b;
echo " </td> \n";
echo "\t <td> ";
echo $app_1;
echo " </td> \n";
echo "\t <td> ";
echo $app_2;
echo " </td> \n";
echo "\t <td> ";
echo $purpose;
echo " </td> \n";
echo "\t <td> ";
echo $tr;
echo " </td> \n";
echo " </tr> \n";
$i++;
}
?>
</table>
</body>
</html>
<?PHP
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Aug 27, 2007 12:26 pm
by miro_igov
Uuunh ugly code. Make sure your variables do not contain html tags.
Posted: Mon Aug 27, 2007 12:52 pm
by billinnc
good point... I had a variable named 'tr'
I changed it, but I still get the occasional broken HTML errors.
the reason for the ugly code is that I thought controlling the whitespace going to the HTML might be a key to fixing the problem.
Posted: Mon Aug 27, 2007 2:13 pm
by pickle
This would be a perfect place for templating - but that's a different story & different matter...
Try putting your output in heredocs
Code: Select all
echo <<<OUTPUT
<tr>
<td>
<a href = "flighttime_detail.php?id=$ID" />$date</a>
</td>
<td>
$aircraft
</td>
...etc
OUTPUT;
That might make it easier to see the code-wise layout of the page.
Also, look at
mysql_fetch_assoc() instead of
mysql_result() - it'll be faster if you're working on any decently sized result set.
Posted: Mon Aug 27, 2007 3:21 pm
by Kieran Huggins
turn off output buffering until the error is resolved - i have a feeling it's capturing your error messages
Posted: Mon Aug 27, 2007 3:25 pm
by billinnc
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
thanks, that cleaned up the code, but I'm still having the same problem.
I changed the php to this...
Code: Select all
echo <<<OUTPUT
<tr>
<td><a href="flighttime_detail.php?id=$ID">$date</a></td>
<td> $aircraft </td>
<td> $model </td>
<td> $tot </td>
<td> $ac </td>
<td> $nt </td>
<td> $nvg </td>
<td> $act </td>
<td> $sim </td>
<td> $app_a </td>
<td> $app_b </td>
<td> $app_1 </td>
<td> $app_2 </td>
<td> $purpose </td>
<td> $training </td>
</tr>
OUTPUT;
$i++;
}
?>
</table>
</body>
</html>
<?PHP
?>
Here is an example of one of the html rows with corrupted syntax...note the additional open tag on the second td element....
Code: Select all
</tr>
<tr>
<td><a href="flighttime_detail.php?id=1087">2007-07-25</a></td>
<</td> aircraft </td>
<td> MV22B </td>
<td> 3.5 </td>
<td> 3.5 </td>
<td> 3.5 </td>
<td> 3.5 </td>
<td> 0 </td>
<td> 0 </td>
<td> 0 </td>
<td> 0 </td>
<td> 0 </td>
<td> 0 </td>
<td> Initial NVG formation and single/section CALS </td>
<td> NS241 NS242 </td>
</tr>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Aug 27, 2007 3:27 pm
by VladSun
I could not replay your error by using your code

What are the values of $date and $aircraft?