[FX.php List] Embed php into HTML or vice versa?
DC
dan.cynosure at dbmscan.com
Thu Aug 31 20:06:19 MDT 2006
If you are not using smarty.... (which you should really take a look
at).... ;-)
A lot of PHP servers have 'short tags' turned on. This can be changed
in php.ini file if it isn't on. you can replace the verbosity of
<?php echo $variable ?>
with the nice
<?=$variable ?>
Also, 'Alternative syntax for control structures" is something to
look at in the PHP manual. Basically it involves using colon to open
foreach and if (and other control structures) and using endforeach;
and endif; to close them.
These two ideas will allow you to tighten up the mixed HTML and PHP
like so (at least i think it's cleaner! I added list-explode line for
clearer variable assigns and I changed the closing anchor tag to be
output in HTML instead of Kevin's suggestion to use a pragmatic PHP
approach since I find it more readable and you avoid escaping
doublequote):
<? foreach($searchResult['data'] as $key => $value):
list($currentRecord, $mod)=explode('.',$key); ?>
<tr class="ver12">
<td>
<a href="famdetail.php?recid=<?=$currentRecord?>" >
<?=$value['FamilyName'][0] ?>
</a>
</td>
<? endforeach; ?>
cheers,
dan
On Aug 31, 2006, at 9:45 PM, Kevin Futter wrote:
> One option would be like so:
>
> <?php
> foreach($searchResult['data'] as $key => $value)
> {
> $recordDetails=explode('.',$key);
> $currentRecord=$recordDetails[0];
> ?>
> <tr class="ver12"><td><a href="famdetail.php?recid=<?php echo
> $currentRecord
> . "\">" . $value['FamilyName'][0]; ?></a></td>
> <?php
> }
> ?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060831/35c25138/attachment.html
More information about the FX.php_List
mailing list