[FX.php List] A nagging question: Foreach

Andy Gaunt andy at fmpug.com
Mon Sep 22 20:26:29 MDT 2008


You can also use the current function for a single record

$value = current($queryResult['data']);

Then you can just echo $value['field'][0];

Also, don't forget that if you have NO related data you can tell your  
query that and drop the [0] completely eg;

$queryResult = FMFind (true, 'full',false);
$value = current($queryResult['data']);
echo $value['field'];

Cheers

Andy


On Sep 22, 2008, at 7:15 PM, Bob Patin wrote:

> Leo,
>
> I use it when I'm pulling data from a single record, like this:
>
> foreach($findResult['data'] as $key => $value);
> $field1 = $value['field1'][0];
> $field2 = $value['field2'][0];
> $field3 = $value['field3'][0];
>
> ... and so on. There's no need for a looping structure since your  
> foundset only has a single record. I use it all the time...
>
> Also, you can use that same method if you want to retrieve the last  
> record in the foundset. Opposite to FileMaker, which always shows  
> you the first record in a foundset after a FIND, this method returns  
> the last record.
>
> So if you get 10 records returned, and use that method above, you'll  
> retrieve the values in the last record of the foundset, based on the  
> sort rules you may have used.
>
> Bob Patin
> Longterm Solutions
> bob at longtermsolutions.com
> 615-333-6858
> http://www.longtermsolutions.com
> iChat: bobpatin
> AIM: longterm1954
> FileMaker 9 Certified Developer
> Member of FileMaker Business Alliance and FileMaker TechNet
> --------------------------
> FileMaker hosting and consulting for all versions of FileMaker
> PHP • Full email services • Free DNS hosting • Colocation • Consulting
>
>
> On Sep 22, 2008, at 6:03 PM, Leo R. Lundgren wrote:
>
>>
>> 23 sep 2008 kl. 00.56 skrev Bob Patin:
>>
>>> Jonathan,
>>>
>>> You can use this:
>>>
>>> foreach($findResult['data'] as $key => $value);
>>>
>>> Notice the semicolon...
>>
>> Bob; What is this syntax for? I've never seen it being used before.  
>> The only thing I can think of it accomplishing is to set $key and  
>> $value to the values of the very last item in the array?
>>
>> -|
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> 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