[FX.php List] A little help with strings and arrays

Andrew Denman adenman at tmea.org
Mon Mar 19 08:08:58 MDT 2007


The following will concatenate the elements of the category array into one
string: http://us3.php.net/manual/en/function.implode.php

$add_result_fields = array('name'=>$_POST['name'],'category'=>$_POST 
['category'],'amount'=>$_POST['amount'],);
$add_result_fields['category'] = implode("\r\n",
$add_result_fields['category']);

* I believe the "\r\n" line separators will work on Mac (it definitely works
on Windows), but if it doesn't work for you on Mac try just "\n".

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 Steve Bennett
Sent: Saturday, March 17, 2007 9:02 PM
To: fx.php_list at mail.iviking.org
Subject: [FX.php List] A little help with strings and arrays

I am trying to modify some code created by the FMStudio Site Builder  
to get a better understanding of FX-PHP and FileMaker. I have been  
able to create a set of checkboxes from a value list on my form but  
can not figure out how to get the checkbox fields from the form into  
FileMaker when creating a new record.


On the form the Category checkbox set is created using the following  
code:

       <?php
foreach(fmsValueListItems($managersitetest,'Expenses','CategoryType')  
as $list_item_key=>$list_item) {
   if( fmsCompareSet($list_item, "") ) {
     echo "<input name=\"category[{$list_item_key}]\" type=\"checkbox 
\" value=\"{$list_item}\" checked=\"checked\">{$list_item}<br>\n";
   } else {
     echo "<input name=\"category[{$list_item_key}]\" type=\"checkbox 
\" value=\"{$list_item}\">{$list_item}<br>\n";
   }
}
?>



The record creation page uses the following code to create a new  
record and fill in the fields from the form:

<?php require_once('../Connections/managersitetest.php'); ?><?php
$add_result_add = clone($managersitetest);
$add_result_add->layout = 'Expenses';
$add_result_fields = array('name'=>$_POST['name'],'category'=>$_POST 
['category'],'amount'=>$_POST['amount'],);
foreach($add_result_fields as $key=>$value) {
     $add_result_add->AddDBParam($key,$value);
}

$add_result_result = $add_result_add->FMNew();

if(is_a($add_result_result,"FX_Error") || $add_result_result 
['errorCode'] != "0") fmsTrapError($add_result_result,"error.php");

$add_result_row = current($add_result_result['data']);
$add_result_row_key = key($add_result_result['data']);
// FMStudioFX v1.0 - do not remove comment, needed for DreamWeaver  
support ?>



 From what I understand I have an array within an array and need to  
change the following section of code, from above, so that it creates  
a string from the array submitted by 'category'

$add_result_fields = array('name'=>$_POST['name'],'category'=>$_POST 
['category'],'amount'=>$_POST['amount'],);


I am not sure how to go about modifying the array within the array or  
if this is where it needs to be done?

Any guidance would be appreciated,

Steve
_______________________________________________
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