broken html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
billinnc
Forum Newbie
Posts: 5
Joined: Fri Aug 17, 2007 10:33 am

broken html

Post 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

Code: Select all

ob_start();
and end with

Code: Select all

ob_end_flush();
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
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Maybe issue in your php code. Post it please.
billinnc
Forum Newbie
Posts: 5
Joined: Fri Aug 17, 2007 10:33 am

Post by billinnc »

feyd | Please use

Code: Select all

,

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

,

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]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Uuunh ugly code. Make sure your variables do not contain html tags.
billinnc
Forum Newbie
Posts: 5
Joined: Fri Aug 17, 2007 10:33 am

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

turn off output buffering until the error is resolved - i have a feeling it's capturing your error messages
billinnc
Forum Newbie
Posts: 5
Joined: Fri Aug 17, 2007 10:33 am

Post by billinnc »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

I could not replay your error by using your code :(
What are the values of $date and $aircraft?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply