You are here: Re: Need another set of eyes on this « PHP Programming Language « IT news, forums, messages
Re: Need another set of eyes on this

Posted by Christoph Burschka on 11/02/07 15:19

Shelly wrote:
> I have been starting and staring at this code snippet and can't seem to find
> anything. Maybe another pair of eyes can. Here is the snippet:
>
> $i = 0;
> $html = '<body><table border="1" align="center"><tr><td colspan="2"
> align="center"><b>' . $title . '</b></td></tr>';
> foreach ($fields as $field) {
> $fieldValue[$field] = $_POST[$field];
> $html .= '<tr><td><b>' . $fieldDisplay[$i] . '</b></td>><td>' .
> $fieldValue[$field] . '</td></tr>';
> $i++;
> }
> $html .= '</table></body>';
> var_dump($html);
>
> The table gets output correctly, but before the table there appear a number
> of lines with only a ">" at the top, aligned with the left edge of the
> table. The number of lines is equal to the number of times through the loop
> (not including the first line before the loop). That is, if there are 9
> fields, then the table has 10 rows and there appeare 9 ">" before the table.
> The values of $fieldDisplay[$i] and $fieldValue[$field] appear correctly in
> the table.
>
> Where is it picking up that extra ">"?
>


Look closely at this bit: '</b></td>><td>'

Never to worry, I've lost staring-contests with my HTML too. ;)

Tip:

You could use more line breaks and indentation, and when you output literal HTML
code, do it directly instead of using print statements where possible. Both of
these methods make the code more readable especially if you have syntax-coloring
in the editor. Errors are far easier to see.

For example:

<body>
<table border="1" align="center">
<tr>
<td colspan="2" align="center">
<b><?=$title?></b>
</td>
</tr>

<?php

foreach ($fields as $field) {
$fieldValue[$field] = $_POST[$field];
?>

<tr>
<td>
<b><?=$fieldDisplay[$i]?></b>
</td>
<td>
<?=$fieldValue[$field]?>
</td>
</tr>

<?php
$i++;
}

</table>
</body>

--
Christoph Burschka <christoph.burschka@rwth-aachen.de>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация