[FX.php List] Help needed to rewrite old FMP tags to PHP ( to achieve different table rows color )

DC dan.cynosure at dbmscan.com
Tue Mar 29 08:46:19 MST 2005


yes. it should work in principle, but there are grave limitations to 
this approach and there are errors in your foreach loop. it also looks 
like you can use short tags in your PHP installation (<??> as opposed to 
long tags <?php?>) Short tags are fine if your server supports them.

the main problem is that your approach only gives you 10 rows! 2nd 
problem is your foreach has a table tag INSIDE the loop. CDML is such a 
limiting language that you have to realize that PHP has tools that 
outdream anything that CDML could ever do - so you have to reorganize 
your approach.

try this instead (uses modulo operator to deal with odd/even):

<table width="100%" border="0" cellpadding="2"cellspacing="0">
<? $searchResult['data']=array(1,2,3,4,5); //dummy array ?>
<? $i=1; ?>
<? foreach($searchResult['data'] as $key=>$searchData){ ?>
  <tr bgcolor="<? if($i%2==1){echo "#DDDDDD";}else{ echo "#AAAAAA";} ?>">
   <td><? echo $value['recid'][0]; ?>
   <td><? echo $searchData['recid'][0]; ?></td>
   <td><? echo $searchData['Headline'][0]; ?></td>
   <td><? echo $searchData['category'][0]; ?></td>
  </tr>
<? $i++; ?>
<? } ?>
</table>

Another approach if you have not moved to FMP 7 yet is simply to call 
your CDML pages from PHP like this:

<? file_get_contents("http://domain.com/old_fmp_cdml_query_here"); ?>

You may have to tweak the CDML so that it doesn't return head or body 
tags but that lets you keep the CDML intact as you migrate to PHP.

As you may know, FMP7 dropped support for CDML.

HTH,
dan

Lars Arlér had written:
> Hi and thanks in advance.
> 
> What I try to achieve is to make every second table row different color,
> Other solution or options are welcome
> 
> Basically I need to make a include statement like this in PHP
>                       <tr [FMP-include:../rowcolor.TXT]>
> Would this work ??
>                       <tr <? include_once('rowcolor.PHP'); ?> >
> 
> ----------------------------------------------------------------------------
>  <? foreach($searchResult['data'] as $key=>$searchData){ ?>
> <table width="100%" border="0" cellpadding="2"cellspacing="0">
> 
> <tr [FMP-include:../rowcolor.txt]>
> 
>    <td><?php echo $value['recid'][0]; ?>
>            <? Echo $searchData['recid'][0]; ?></td>
>   <td><? echo $searchData['Headline'][0]; ?></td>
>   <td><? echo $searchData['category'][0]; ?></td>
> 
> </tr>
> </table>
>     <? } ?>
> -----------------------------------------------------------------------
> 
> 
> --------------    included   rowcolor.TXT    -------------------------------
> [FMP-IF: 
> CurrentRecordNumber .eq. 1] BGCOLOR="#DDDDDD"
> [FMP-Else]
> [FMP-IF:
> CurrentRecordNumber .eq. 3] BGCOLOR="#DDDDDD"
> [FMP-Else]
> [FMP-IF:
> CurrentRecordNumber .eq. 5] BGCOLOR="#DDDDDD"
> [FMP-Else]
> [FMP-IF:
> CurrentRecordNumber .eq. 7] BGCOLOR="#DDDDDD"
> [FMP-Else]
> [FMP-IF:
> CurrentRecordNumber .eq. 9] BGCOLOR="#DDDDDD"
> 
> [/FMP-IF]
> [/FMP-IF]
> [/FMP-IF]
> [/FMP-IF]
> [/FMP-IF]
> -------------------------------------------------------------------------
> 
> --------------    included   rowcolor.PHP    -------------------------------
> If($CurrentRecordNumber ==`1`){`BGCOLOR="# DDDDDD"`); }
> else
> If($CurrentRecordNumber ==`3`){`BGCOLOR="# DDDDDD"`); }
> else
> If($CurrentRecordNumber ==`5`){`BGCOLOR="# DDDDDD"`); }
> Else
> If($CurrentRecordNumber ==`7`){`BGCOLOR="# DDDDDD"`); }
> else
> If($CurrentRecordNumber ==`9`){`BGCOLOR="# DDDDDD"`); }
> Else
> -------------------------------------------------------------------------
> 
> 
> Lars Arlér
> 
> 
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
> 


More information about the FX.php_List mailing list