[FX.php List] Generating Safe links to Database Records

Malcolm Fitzgerald malcolm at notyourhomework.net
Tue Jan 17 18:28:39 MST 2012


That's terrific. I'll borrow that straight away. I have been using this terminology:  foreach( $queryResult as $key=>$field ) { }. Which allows me to say, eg, $field['State'], within the loop which is fairly plain english. I've also learnt to use the foreach block to traverse a result array that only contains one record, as it is much more convenient to access the array in this manner. 

In the course of being confused about the record id I did clarify something and it will be useful down the track. That is, if you ask FX to find the record id using "recid.modnbr" it will succeed if the modification number is correct. The search fails if modnbr is different. 

My data was very static, so I was getting the results I wanted when using "recid.modnbr" until one of the records changed during testing. So, for building web page links it is important to use "recid" alone. For managing changes, the "recid.modnbr" combination can provide a simple test for changes.

Malcolm




On 18/01/2012, at 12:58 AM, Steven Thoms wrote:

> Malcolm,
> 
> I use this to make the result['data'] array more useable:
> 
> function simplifyData($data) {
>   $newArray = array();
>   $i=0;
>   foreach( $data as $key=>$fieldArray ) {
>       $FMPids = explode(".",$key);
>       $newArray[$i]['recid'] = $FMPids[0];
>       $newArray[$i]['modid'] = $FMPids[1];
>       foreach( $fieldArray as $field=>$value ) {
>           if ( is_array ( $value ) && isset ( $value[0] ) ) {
>               if ( substr($value[0], 0, 3) == '*!*' )
>                   $newArray[$i][$field] = substr($value[0], 3);
>               else
>                   $newArray[$i][$field] = nl2br($value[0]);
>           } else {
>               $newArray[$i][$field] = '';
>           }
>       }
>   $i++;
>   }
>   /* i.e. Array
>   (
>       [0] => Array
>           (
>               [recid] => 3
>               [modid] => 575
>               [account_active] => 1
>               [account_name] => sthoms
>               [account_pass] => password
>               [full_name_c] => Steve Thoms
>               [security_level] => 1
>           )
> 
>   )
>   */
>   return $newArray;
> }
> 
> Steve
> 207 798-0171
> 
> On Jan 16, 2012, at 7:18 PM, Malcolm Fitzgerald wrote:
> 
>> 
>> On 17/01/2012, at 11:02 AM, Malcolm Fitzgerald wrote:
>> 
>>> This morning I was testing a routine and the results looked odd. After some head-scratching I increased the modification number on the record and got the right results. The record id returned by FX consists of the internal record ID and it's modification number. The modification number is inherently unstable.
>>> 
>>> I want to be able to generate links to records in the database that do not rely on the modification number. How does FX handle this?
>> 
>> I'll answer my own question.
>> 
>> Searching by -recid works perfectly well as the key to access data but it is not sufficient to act as a key for the data array which is returned. The returned array has a key which consists of the internal record ID and it's modification number. There should only be one item returned array so it is easy to access.
>> 
>> Malcolm_______________________________________________
>> 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