[FX.php List] Getting "-recid" for 1 record

DC dan.cynosure at dbmscan.com
Tue Jul 18 18:27:39 MDT 2006


sorry...

i didn't take a really close look at what you had... i think gtt's  
answer will fix your problem...

however, i looked at your original question and it seems that if you  
get more than one record returned in the found set you may want an  
array of recids and their modcounts? is that the case?

here's how you could do that (I took your challenge that you wanted  
to avoid repeat loops so this makes use of PHP's array functions  
instead):

<?php
// show how to get an assoc array from FX.php data
// with rec id as key and mod count as value
// dummy data similar to FX.php array
$ResultAll['data'] = array('1000.11'=>1,'2000.22'=>2);

// get the keys which are the in the format recid.modcount
$keys_array = array_keys($ResultAll['data']);
// map array to custom function
// generate dots for explode
$dots_array = array_fill(0,count($keys_array),'.');
$modid_recid_array = (
				array_map('explode_to_assoc',
				$dots_array,
				$keys_array)
				);
print_r($modid_recid_array);

// ---------------------------------------
// assumes 2 items separated by $str incoming
// returns assoc array with item 1 as key
// and item 2 as value
function explode_to_assoc ($str, $arr) {
	list($i,$j) = explode($str,$arr);
	return array($i=>$j);
}
?>

archived at:

http://dbmscan.com/snippets/

in the FX helpers section.


enjoy!
dan

On Jul 18, 2006, at 5:13 PM, AC wrote:

> This is the command I'm using:
> $ResultAll=$Search->FMFindAny();
> list($TheRecID, $TheModID)=explode('.', ($ResultAll['data']));
> echo('RecID=' . $TheRecID);
>
> The result I get is;
> RecID=Array
>
>
>
> On Jul 18, 2006, at 4:05 PM, DC wrote:
>
>> take out $key
>>
>> AC had written:
>>> This works for me;
>>> $ResultAll=$Search->FMFindAny();
>>> list($key)=each($ResultAll['data']);
>>> $TheRecID=strtok($key, ".");
>>> I can't get this to work, did I miss type it or does it require  
>>> the for each loop?
>>> $ResultAll=$Search->FMFindAny();
>>> list($TheRecID, $TheModID)=explode('.', $key($ResultAll['data']));
>>> On Jul 18, 2006, at 3:09 PM, Gjermund Gusland Thorsen wrote:
>>>> This is how I do it
>>>> ---
>>>> list( $recid, $modid ) = explode( '.', $key( $r['data'] ) );
>>>> ---
>>>>
>>>> ggt667
>>>>
>>>> On 7/18/06, AC <ac at pottnerconsulting.ca> wrote:
>>>>
>>>>> > If you just want the key I believe this will work, but I  
>>>>> haven't tried:
>>>>> > list($key) = each($ResultAll['data']);
>>>>> > $recid = strtok($key, ".");
>>>>>
>>>>> Yes it does work, thanks.
>>>>>
>>>>>
>>>>>
>>>>> On Jul 18, 2006, at 1:52 PM, Andrew Denman wrote:
>>>>>
>>>>> > Don't remember where I found this, but it's useful if you  
>>>>> only have one
>>>>> > record returned. The first line will give you the key and  
>>>>> data of the
>>>>> > first
>>>>> > set of data in the $ResultAll['data'] array (and according to  
>>>>> the php
>>>>> > docs,
>>>>> > advance the pointer to the next set of data).  Second and  
>>>>> third lines
>>>>> > will
>>>>> > break out the recid and modid.
>>>>> >
>>>>> > list($key, $data) = each($ResultAll['data']);
>>>>> > $recid = strtok($key, ".");
>>>>> > $modid = strtok(".");
>>>>> > $Field_Data = $data['Field_Name'][0];
>>>>> >
>>>>> > If you just want the key I believe this will work, but I  
>>>>> haven't tried:
>>>>> > list($key) = each($ResultAll['data']);
>>>>> > $recid = strtok($key, ".");
>>>>> > $modid = strtok(".");
>>>>> >
>>>>> > Andrew Denman
>>>>> >
>>>>> > -----Original Message-----
>>>>> > From: fx.php_list-bounces at mail.iviking.org
>>>>> > [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of AC
>>>>> > Sent: Tuesday, July 18, 2006 12:30 PM
>>>>> > To: fx.php_list at mail.iviking.org
>>>>> > Subject: [FX.php List] Getting "-recid" for 1 record
>>>>> >
>>>>> > If I know that only 1 record is returned then I can use the  
>>>>> following
>>>>> > to get data from that record;
>>>>> >
>>>>> > $ResultAll=$Search->FMEdit();
>>>>> > $ResultOne=current($ResultAll['data']);
>>>>> > echo('ID=' . $ResultOne['ID'][0]);
>>>>> >
>>>>> >
>>>>> >
>>>>> > How would I do the same thing to get the "-recid" without  
>>>>> doing the
>>>>> > following loop thing?
>>>>> >
>>>>> > foreach($ResultAll['data'] as $key=>$ResultOne){
>>>>> >     $TheRecIDModNum=explode('.',$key);
>>>>> >     $TheRecID=$TheRecIDModNum[0];
>>>>> > }
>>>>> >
>>>>> > _______________________________________________
>>>>> > 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