Jump to content

Archived

This topic is now archived and is closed to further replies.

ev66

help with syntax

Recommended Posts

Im using this code below to place the value of $a into first cell of a table, what is the correct syntax so that i only have to use one echo statement ? tried all diff combinattions but cant get it.
Thanks

<body>[color=red]<?php[/color] [color=blue]echo '<table width="400" border="1">
  <tr>
    <td>'; echo $a; echo '&nbsp;</td>[/color]
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
'
[color=red]?>[/color]

Share this post


Link to post
Share on other sites
Use HEREDOC:
[code=php:0]<?php echo <<<HTML
<table width="400" border="1">
  <tr>
    <td>{$a}</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
HTML;
// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE
?>[/code]


Or use this, not the use of the concatenation operator (.)
[code=php:0]<?php echo '<table width="400" border="1">
  <tr>
    <td>' . $a . '</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>'; ?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.