[FX.php List] Newbie Needs Help

Chris Hansen chris at iViking.org
Mon Oct 17 12:34:40 MDT 2005


Peter,

Thanks for your patience.  I'm going to answer you on the list  
because I think that what you're asking about may be helpful to  
others, as well.  Details follow:


_Alternating_Colors_in_Table_Rows__

There are a number of important elements to note here...

1) You'll want some way of dependably tracking which physical table  
row you're on.  I often do this with a variable called $counter which  
I then increment manually each time through the loop (i.e. ++$counter).

2) Use of the modulus (%) operator.  For those not of a mathematical  
background, modulus outputs the remainder from a division operation.   
So, any number modulus 2 would be either 0 (a number divisible by 2)  
or 1.  Make sense?  So instead of this (from the example you sent me):

<?
foreach($searchResult['data'] as $key=>$searchData){ ?>
<tr>

Do something like this:

<?
$counter = 0;
foreach($searchResult['data'] as $key=>$searchData) {
     if ($counter % 2 == 0) {
         echo("    <tr bgcolor=\"#FFFFFF\">\n");
     } else {
         echo("    <tr bgcolor=\"#CCCCCC\">\n");
     }
?>

Of course, you may want to use CSS, etc. (like Andy did in his  
response) but hopefully this demonstrates the point. And as a  
reminder, DON'T FORGET TO INCREMENT YOUR COUNTER.  Usually it's best  
to do this at the bottom of the loop (just in case there are other  
places in the loop where counting is useful.


_Human_Readable_Errors__

The FX.php distribution includes a file called 'FMErrors.php' which  
is basically a long PHP array of FileMaker error codes, and their  
human readable equivalents.  (Note that in the latest release this  
file has been moved to the 'Developer' sub-directory.)  If you want  
to output a human readable error for an error stored in the  
'errorCode' element of the returned FX array (called $searchResult,  
like the example above), you'd do something like this:

echo($errorsList[$searchResult['errorCode']]);

Of course this only works with FileMaker errors, but it's a start.   
Also, you'll want to check the returned error code and output the  
error if it's not equal to zero, or perform your foreach() loop if  
there is no error.  So, with error checking, the example above might  
look like this (I've assumed a four column table display):

<?
if (FX::isError($searchResult) || $searchResult['errorCode'] != 0) {
     if (FX::isError($searchResult)) { // non-FileMaker Errors are  
handled first
         $errorMessage = $searchResult->message;
     } else { // now handle FileMaker errors
         $errorMessage = $errorsList[$searchResult['errorCode']];
     }
     echo('<tr><td colspan="4">' . $errorMessage . "</td></tr>\n");
} else {
     $counter = 0;
     foreach($searchResult['data'] as $key=>$searchData) {
         if ($counter % 2 == 0) {
             echo("    <tr bgcolor=\"#FFFFFF\">\n");
         } else {
             echo("    <tr bgcolor=\"#CCCCCC\">\n");
         }
         /* remainder of record display code /*
     } // this curly brace closes the foreach
} // this curly brace closes the else
?>

I hope this is clear.  I realize that reading other people's coding  
can be a challenge, and I don't know that I could give this topic  
sufficient coverage here.  Hopefully this clears things up  
sufficiently for you to move forward.  Best,


Chris Hansen
Application Developer
The Moyer Group
Phone: (801) 796-1677
Fax: (404) 377-1395
chansen at moyergroup.com
http://www.moyergroup.com/
-
Creator of FX.php
"The best way from FileMaker to the Web."
http://www.iViking.org/


On Oct 17, 2005, at 11:36 AM, Peter Bates wrote:

> Brief about myself: I've just started using FX.php, (I was using  
> FileMaker's XSLT), for my custom web publishing. My knowledge of  
> php is at the learning stages too. I have FX.php in 8 Hours, (book  
> and video series), and FXForge 2.0.
>
> I have been able to understand most of the code that is produced by  
> FXForge, but when it comes to the code that is provided by Chris  
> Hansen's examples that he provides, I quickly get lost, since his  
> code is structured so much differently that the FXForge-produced  
> code. I've been trying for weeks now to integrate two features that  
> he provides in his index.php code into my search_results.php code  
> without any success. If anyone could please help me understand how  
> to do the following two items, I would be eternally grateful.
>
> In his Book List Example, he shows:
> 1. The data rows displayed in alternating colors.
> 2. A "plain english" message is returned when no records are found.
>
> That's it. I can see where in his code that he does this, but I  
> just don't understand how to get the same results with my code.  
> This is the only bit that I lack to consider my code to be  
> complete. The URL for this is at:  http://fmcwp.sjcpl.org/tribindex/ 
> index.php
>
> Peter Bates
>
>
> _______________________________________________
> 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