[FX.php List] in_array code fragment

DC dan.cynosure at dbmscan.com
Fri Sep 15 09:46:51 MDT 2006


Hi David,

This question means that you haven't yet come to terms with the way  
that FX.php returns the data. It is a nested, associative array. You  
need to become familiar with it to progress.

You're quite right. You are accessing the referenceNumber_array  
wrong. In fact, you have some extra work to do before you can get to  
the data that you need for this comparison to work properly.

This line:
> $referenceNumber_array = $Query->FMFind();

is going to return multiple records separated into multiple nested  
arrays.

To get one record for comparison is easy and very similar to what  
you've already done.
> $referenceNumber_array['data'][0]['referenceNumber'][0]

This describes the 'location' of a single piece of data in the FX.php  
array. Reading from right-to-left... It says give me the first array  
item [0] returned for the filemaker field 'referenceNumber' for the  
first record returned [0] at the array location 'data'. phew.

To get all these bits of data from multiple returned records is what  
you want to do. You need to get the data bits (referenceNumbers) into  
an array that you can use with the in_array function. I could write  
it out for you but then you wouldn't have that keen sense of  
accomplishment when you've finished... ;-)

HOWEVER,
If you have control over the FMP database then you can do something  
potentially easier :
make a self join on customernumber and use it to build a calculation  
field that contains all the reference numbers. (in FMP6 i've used  
troitext plugin to do this, not sure if this is now possible natively  
with FMP7 or FMP8) put that field on your layout and use that field  
instead to do a simple strpos() check. this will allow you to do one  
find and one duplicate check. note that this assumes that all your  
referenceNumbers are unique. doing it this way means you don't have  
to fuss around with un-nesting FX.php data array.

either way you choose, let us know.

dan

On Sep 15, 2006, at 11:30 AM, David Ness wrote:

> Here's that code fragment again, with the formatting fixed (hopefully)
> for clarity.
>
>
> // Read in all values contained in the referenceNumber field from FM
> // Layout 'referenceNumberLayout' contains 2 fields:
> // 'customer_number' & 'referenceNumber'
> $Query = new FX($serverIP,$webCompanionPort);
> $Query->SetDBData($databasename,'referenceNumberLayout', 'all');
> $Query->SetDBPassword($password,$username);
> $Query->AddDBParam('customer_number', $customerNumber, "eq" );
> $referenceNumber_array = $Query->FMFind();
>
>
> while (($importdata = fgetcsv($handle, 0, ",")) != FALSE) {
>     // Check to see if Builder Ref#/Job# is unique for this builder.
>     // This is the mechanism for handling (excluding) duplicate
> submissions.
>     // $importdata[0] contains the reference number
>     if( in_array( $importdata[0],
> $referenceNumber_array['referenceNumber'] )) {
>         $validationMsg = 'Skipped';
>     }
> }
>
>
> --
> David Ness,
> Database Systems Programmer
> _______________________________________________
> 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