[FX.php List] Current function

Anders Monsen andersm at alamark.com
Thu Nov 13 12:31:28 MST 2008


I have three options working. I included one extra field in the sample  
code since I need to get both the recid and a list of fields, where  
the recid is not defined as a field. I'm not sure if there is a best  
method, but I like the idea of not needing a foreach for just a single  
record.

Thanks,
Anders

$resultAcct = $fmAcct->FMFind(true, 'full', false);

OPTION 1:
foreach($resultAcct['data'] as $key=>$current) {
	$recid = $recordDetails[0];
	$nameFirst	= $current['Name_first'];
}

OPTION 2;
foreach($resultAcct['data'] as $key=>$current) {
	list( $recid, $modid ) = explode( '.', $key );
	$nameFirst	= $current['Name_first'];
}

OPTION 3:
foreach($findResult['data'] as $key=>$findData);
$current			= current($resultAcct['data']);
list($recid, $modid) = explode('.',key($resultAcct['data']));
$nameFirst		= $current['Name_first'];




On Nov 13, 2008, at 1:15 PM, Gjermund Gusland Thorsen wrote:

> Steve I believe you have to wrap the content of key() in current()
>
> ggt
>
> 2008/11/13 Steve Winter <steve at bluecrocodile.co.nz>:
>>
>> Or if you only want the first value record returned from the  
>> database, which
>> Anders' use of current() is going to give then you should be able  
>> to do;
>>
>>       list($recid, $modid) = explode('.',key($queryResult['data']));
>>
>> He theorises while sitting on a train with now way of testing this...
>>
>> Cheers
>> Steve
>>
>> On 13 Nov 2008, at 19:08, Gjermund Gusland Thorsen wrote:
>>
>>> Ehh $key=>$queryData not $key=$queryData
>>>
>>> ggt
>>>
>>> 2008/11/13 Bob Patin <bob at patin.com>:
>>>>
>>>> Hey G,
>>>>
>>>> How do I use that? Do I put that line after a FOREACH?
>>>>
>>>> I tried doing this:
>>>>
>>>> foreach($queryResult['data'] as $key=$queryData);
>>>> list( $recid, $modid ) = explode( '.', $key );
>>>> echo $recid;
>>>>
>>>> and I get nothing...
>>>>
>>>> Thanks,
>>>>
>>>> Bob
>>>>
>>>>
>>>> On Nov 13, 2008, at 12:13 PM, Gjermund Gusland Thorsen wrote:
>>>>
>>>>> list( $recid, $modid ) = explode( '.', $key );
>>>>>
>>>>> ggt667
>>>>>
>>>>> 2008/11/13 Bob Patin <bob at patin.com>:
>>>>>>
>>>>>> Maybe I'm missing something here, but I find it much simpler to  
>>>>>> put a
>>>>>> calc
>>>>>> field in my tables to retrieve the recid, and then I pull in  
>>>>>> that field
>>>>>> when
>>>>>> I pull in other fields. It only takes a single line of code,  
>>>>>> and the
>>>>>> field
>>>>>> in FM is simply recid=get(recordid).
>>>>>>
>>>>>> Bob Patin
>>>>>> Longterm Solutions LLC
>>>>>> bob at longtermsolutions.com
>>>>>> 615-333-6858
>>>>>> http://www.longtermsolutions.com
>>>>>> iChat/AIM: bobpatin
>>>>>> FileMaker 9 Certified Developer
>>>>>> Member of FileMaker Business Alliance
>>>>>> --------------------------
>>>>>> FileMaker hosting and consulting for all versions of FileMaker
>>>>>> PHP • Full email services • Free DNS hosting • Colocation •  
>>>>>> Consulting
>>>>>>
>>>>>> On Nov 13, 2008, at 11:26 AM, Anders Monsen wrote:
>>>>>>
>>>>>>> Revisiting this function, is it possible to get the FileMaker  
>>>>>>> record
>>>>>>> ID
>>>>>>> via current( )? I use this to pull fields from a found set of  
>>>>>>> one, and
>>>>>>> I
>>>>>>> need to send over the recid in a form.
>>>>>>>
>>>>>>> Until now I have been using something like this:
>>>>>>>
>>>>>>> foreach($createResult['data'] as $key=>$value) {
>>>>>>>   $recordDetails = explode('.',$key);
>>>>>>>   $currentRecord = $recordDetails[0];
>>>>>>> }
>>>>>>>
>>>>>>> While I like the elegance of current( ), I am not sure how to  
>>>>>>> isolate
>>>>>>> the
>>>>>>> recid piece, which would be very useful.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Anders
>>>>>>>
>>>>>>> On Sep 22, 2008, at 9:26 PM, Andy Gaunt wrote:
>>>>>>>
>>>>>>>> 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
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> 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
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>
>>>> _______________________________________________
>>>> 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
>>
>>
>> _______________________________________________
>> 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